判断邮箱是否合法
const regExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
return regExp.test(email)
判断电话号码是否合法
const regExp = /^(((13[0-9])|(14[0-9])|(17[0-9])|(15[0-3])|(15[4-9])|(18[0-9])|(199))+\d{8})$/
return regExp.test(phone)
验证是否是中文字符串
const regExp = /^[\u4E00-\u9FA5]+$/
return regExp.test(name)
验证身份证号码是否合法
const 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(idCard)) {
if (idCard.length === 18) {
let idCardWi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10,5, 8, 4, 2];
let idCardY = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2];
let idCardWiSum = 0;
for (let i = 0; i < 17; i++) {
idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
}
let idCardMod = idCardWiSum % 11;
let idCardLast = idCard.substring(17);
if (idCardMod === 2) {
return idCardLast === "X" || idCardLast === "x";
} else {
return idCardLast === idCardY[idCardMod];
}
}else{
return true;
}
} else {
return false;
}