声明:
// 验证邮箱的规则
var checkEmail = (rule,value,cb)=>{
// 验证邮箱的正则表达式
const regEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/
if(regEmail.test(value)){
// 合法的邮箱
return cb()
}
cb(new Error('请输入合法的邮箱'))
}
//验证手机号的规则
var checkMobile = (rule,value,cb)=>{
//验证手机号的正则表达式
const regMobile = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/
if(regMobile.test(value)){
return cb()
}
cb(new Error('请输入合法的手机号'))
}
使用:
email:[{ required: true, message: '请输入邮箱', trigger: 'blur' },{validator:checkEmail,trigger:'blur'}],
mobile:[{ required: true, message: '请输入手机', trigger: 'blur' },{validator:checkMobile,trigger:'blur'}]
//验证带*号的手机号 例:135****1234
telephone: {
required: true,
type:"string",
trigger: 'blur',
message: '请输入正确的手机号',
pattern:/^1[3456789][0-9]([0-9]|\*){4}\d{4}$/
},
其它:
export const isPhone = /^1(3[0-9]|4[5,8]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,6,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
export const isName = /^[\u4e00-\u9fa5a-zA-Z0-9]{1,31}$/;
export const isCertificateNum = /^[a-zA-Z0-9]{1,20}$/;
export const isCarNum =
/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]-[A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]-[A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
// export const isCarNum = /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z]{1}[A-Z]{1}(([0-9]{5}[DF])|(DF[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})$/
// 身份证号码
export const isCreditCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
export const isText = /[\u4E00-\u9FA5]/g;
export const isLetter = /[a-zA-Z0-9]/g;
export const isEnglish = /[a-zA-Z]/g;
export const isEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
export const isPackageName = /^[\u4e00-\u9fa5_a-zA-Z0-9_]{1,32}$/;
//export const isPassWord = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{10,16}$/; // 密码长度必须大于10位小于16位,且必须包含大小写字母、数字
export const isPassWord = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,100}/;