let string = ''; let regex = ''; switch (this.form.identity[i].idType) { case '1020002': string = 'MAC'; regex = /^[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}-[A-F0-9]{2}$/; break case "1021901": string = 'IMEI'; regex = /^\d{15}$/ // 验证为15位数字 break case "1020003": string = 'IMSI'; regex = /^\d{15}$/ // 验证为15位数字 break case "1030001": string = 'QQ'; regex = /^[1-9][0-9]{4,11}$/ break case "1020004": string = '手机'; regex = /^[1][0-9][0-9]{9}$/ break case "1021111": string = '身份证'; regex = /^\d{15}|\d{}18$/ break case "1030036": string = '微信'; regex = /^[a-zA-Z0-9_-]{5,19}$/ break case "1021353": string = '车牌号(需大写),'; if (this.form.identity[i].idCode.length === 7){ regex = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/; } else { // 新能源汽车 regex = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/; } break } if (!regex.test(this.form.identity[i].idCode)) { this.alertToggle({alertType: 'warning', alertContent: string + "格式不正确,请检查"}) flag = false; break; }
js常用正则校验
最新推荐文章于 2024-07-09 16:10:37 发布