其中正则表达式:/^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(199[0-9]{8})|(15[0-9]{9})$/;
data() {
var validatePhone = (rule, value, callback) => {
let mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(199[0-9]{8})|(15[0-9]{9})$/;
if (!mobile.test(value)){
return callback(new Error('请填写正确的手机号'));
}else {
callback();
}
};
return {
ruleForm2: {
phone: '',
},
rules2: {
phone: [
{ validator: validatePhone, trigger: 'blur' }
],
},
},
其中正则表达式:/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
data() {
var validateEmail = (rule, value, callback) => {
let ema = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
if (!ema.test(value)){
return callback(new Error('请填写正确的邮箱'));
}else {
callback();
}
};
return {
ruleForm2: {
email: '',
},
rules2: {
email: [
{ validator: validateEmail, trigger: 'blur' }
],
},
},
其中正则表达式: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/;
data() {
var validateTel = (rule, value, callback) => {
let telNum = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/;
if (!telNum.test(value)){
return callback(new Error('请填写正确的联系电话'));
}else {
callback();
}
};
return {
ruleForm2: {
tel: '',
},
rules2: {
tel: [
{ validator: validateTel, trigger: 'blur' }
],
},
},
onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;"
5、url
[a-zA-z]+://[^\s]*
或
^([hH][tT]{2}[pP]:/*|[hH][tT]{2}[pP][sS]:/*|[fF][tT][pP]:/*)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\\\/])+(\\\\?{0,1}(([A-Za-z0-9-~]+\\\\={0,1})([A-Za-z0-9-~]*)\\\\&{0,1})*)$