首先感谢参考大佬们的博客:
以下是我的一些补充:
var validateMobilePhone = (rule, value, callback) => {
if (value === '') {
callback(new Error('负责人手机号不可为空'));
} else {
if (value !== '') {
var reg=/^1[3456789]\d{9}$/;
if(!reg.test(value)){
callback(new Error('请输入有效的手机号码'));
}
}
callback();
}
};
获取值
rules: {
telephone: [{ validator: validateMobilePhone, trigger: 'blur' }]
}
var validateEmail = (rule, value, callback) => {
if (value === '') {
callback(new Error('请正确填写邮箱'));
} else {
if (value !== '') {
var reg=/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if(!reg.test(value)){
callback(new Error('请输入有效的邮箱'));
}
}
callback();
}
};
取值
rules: {
mail: [{ validator: validateEmail, trigger: 'blur' }],
}
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请设置正确格式的密码'));
} else if(value.length < 6){
callback(new Error('密码长度最小6位'));
}else{
callback();
}
};
var validatePhone = (rule, value, callback) => {
if (value === '') {
callback(new Error('机构电话不可为空'));
} else {
if (value !== '') {
var reg =/^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
if(!reg.test(value)){
callback(new Error('请输入正确的手机号或者座机号格式为:0000-0000000'));
}
}
callback();
}
};
var validateWeixin = (rule, value, callback) => {
if (value === '') {
callback(new Error('微信号不能为空'));
}else{
var reg= /^[a-zA-Z][a-zA-Z0-9_-]{5,19}$/;
if(!reg.test(value)){
callback(new Error('请输入正确的微信号码'));
}else{
callback();
}
}
};
reg= /^[A-Z0-9]{8}-[A-Z0-9]$|^[A-Z0-9]{8}-[A-Z0-9]-[0-9]{2}$/;
reg = /^(([1-9]\d*(\.\d{1,2})?)|(0\.\d{1,2}))$/;
推荐博客1:
https://blog.csdn.net/weixin_43970743/article/details/88532307?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
推荐博客二:
https://blog.csdn.net/qq_38661984/article/details/99968253?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param