https://mp.weixin.qq.com/s/q5unQQkq7wl0XtulCLfcXw
export const checkStr = (str, type) => {
switch (type) {
case 'phone': //手机号码
return /^1[3|4|5|6|7|8|9][0-9]{9}/.test(str);
case 'card': //身份证
return /(\d{15}$)|(^\d{18}$)|(\d{17}(\d|X|x)/.test(str)
case 'postal': //邮政编码
return /[1-9]\d{5}(?!\d)/.test(str);
case 'QQ': //QQ号
return /^[1-9][0-9]{4,9}/.test(str);
case 'money': //金额(小数点2位)
return /^\d(?:.\d{0,2})?/.test(str) || /^(\d{4})-(\d{2})-(\d{2})
/.test(str);
case 'english': //英文
return /^[a-zA-Z]+/.test(str);
case 'lower': //小写
return /^[a-z]+/.test(str);
case 'HTML': //HTML标记
return /<("[^"]"|'[']*'|['">])*>/.test(str);
default:
return true;
}
}








网友评论