验证手机号
/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
匹配重复数字字母 例:1122 qqwww 111qqq www222等
/^([\d])\1{1,9}([a-z])\2{1,9}|([a-z])\3{1,9}([\d])\4{1,9}|([\d])\5{1,9}([\d])\6{1,9}|([a-z])\7{1,9}([a-z])\8{1,9}$/
匹配8-20位数字字母
/^[0-9A-Za-z]{8,20}$/
验证8-18位数字字母组合密码
/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,18}$/
银行卡号
/^\\d{15,21}$/
验证身份证
let regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
if (regIdCard.test(value)) {
if (value.length == 18) {
let idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
let idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2);
let idCardWiSum = 0;
for (let i = 0; i < 17; i++) {
idCardWiSum += value.substring(i, i + 1) * idCardWi[i];
}
let idCardMod = idCardWiSum % 11;
let idCardLast = value.substring(17);
if (idCardMod == 2) {
if (idCardLast == "X" || idCardLast == "x") {
//身份证号码正确
this.sendRequest();
return;
} else {
Alert.warn('身份证号码错误', 1500);
return;
}
} else {
if (idCardLast == idCardY[idCardMod]) {
//身份证号码正确
this.sendRequest();
return;
} else {
Alert.warn('身份证号码错误', 1500);
return;
}
}
}
} else {
Alert.warn('身份证号码错误', 1500);
}
判断图片格式
var rFilter = /^(image\/jpeg|image\/png|image\/jpg)$/i; // 检查图片格式
if (!rFilter.test(file.type)) {
alert("请选择jpeg、png、jpg格式的图片")
return;
}
网址http/https
const HTTP_REGEX = /^(https?|ftp|file):\/\/.+$/
const HTTP_RES = HTTP_REGEX.test(decodeURIComponent(return_url))
汉字
const NAME_REGEX = /^[\u4e00-\u9fa5\w]{1,10}$/
const NAME_RES = NAME_REGEX.test(name)
1-100位汉字/数字/字母/特殊字符组合
特殊字符只包含,。,.??不包含空格以及其他特殊字符
const AUDIO_REGEX = /^[\u4e00-\u9fa5\w/,/./。/,/?/?]{1,100}$/
const AUDIO_RES = AUDIO_REGEX.test(audio_text)