日照项目的居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

123 lines
3.1 KiB

'use strict';
/**
* 表单验证规则
*/
export default {
required: {
message: '该字段必填',
check(v) {
const type = typeof v;
if (type === 'string') {
return v !== '';
} else if (type === 'array') {
return v.length > 0;
} else if (type === 'boolean') {
return v;
} else if (type === 'number') {
return true;
return v !== 0;
} else if (type === 'object') {
return v !== null && v !== undefined;
} else {
return true;
}
}
},
// 最小
min: {
message: '超过最小限制',
check(v, param) {
return parseFloat(v) >= parseFloat(param) || v === '';
}
},
// 最大
max: {
message: '超过最小限制',
check(v, param) {
return parseFloat(v) <= parseFloat(param) || v === '';
}
},
//只能数字、字母、下划线组合,下划线不能在开头或结尾
user: {
message: '只能数字、字母、下划线组合,下划线不能在开头或结尾',
check(v) {
return /^(?!_)(?!.*?_$)(\w)*$/.test(v) || v === '';
}
},
//身份证号 或者护照号
idCard: {
message: '',
check(v) {
return /^([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]))$|(^[a-zA-Z]{2}\d{7}$|^[a-zA-Z]{1}\d{8}$)/.test(v) || v === '';
}
},
// 手机号
mobile: {
message: '手机号格式不正确',
check(v) {
return /^1[23456789]{1}[0-9]{9}$/.test(v) || v === '';
}
},
//url地址
url: {
message: 'url地址格式不正确',
check(v) {
return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(v) || v === '';
}
},
//汉字
chinese: {
message: '仅限汉字',
check(v) {
return /^[\u4e00-\u9fa5]*$/.test(v) || v === '';
}
},
//数字
number: {
message: '仅限数字',
check(v) {
return /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(v) || v === '';
}
},
//数字或字母
alphaNum: {
message: '仅限字母或数字',
check(v) {
return /^[A-Za-z0-9]+$/.test(v) || v === '';
}
},
//整数
digits: {
message: '仅限整数',
check(v) {
return /^\d+$/.test(v) || v === '';
}
},
//范围长度
rangeLength: {
message: '请输入指定范围长度',
check(v, param) {
let length = v.length;
if (Array.isArray(param)) {
return (length >= param[0] && length <= param[1]) || v === '';
} else {
return length == param || v === '';
}
}
},
//范围
range: {
message: '',
check(v, param) {
return (v >= param[0] && v <= param[1]) || v === '';
}
},
//等于
equal: {
message: '两次输入不一致',
check(v, param) {
return v == param || v === '';
}
}
};