igi_orion_cignacmb
Version:
Censors words out of text
47 lines (41 loc) • 1.83 kB
JavaScript
var CentralValidate = { //总的
validate: function (name, value,type) { //用于验证,如有错误,返回数组,便于前端提示
var that = this;
var errors = [];
for (var key in that) {
if (typeof (that[key]) == "function" && key != "validate") {
var runningFunc = that[key](value);
if (!runningFunc.isCorrect) {
if (key == "notNull") {
if(type=="input"||type=='idcard'||type=='input_email'){
errors.push({type: runningFunc.type, msg: '请输入' + name, code: runningFunc.code});
}else{
errors.push({type: runningFunc.type, msg: '请选择' + name, code: runningFunc.code});
}
} else {
if (runningFunc["isUse"]) {
errors.push({type: runningFunc.type, msg: runningFunc.msg, code: runningFunc.code});
} else {
errors.push({type: runningFunc.type, msg: runningFunc.msg, code: runningFunc.code});
}
}
}
}
}
return errors.length > 0 ? errors : null;
},
notNull: function (value) { //用于验证,如有错误,返回数组,便于前端提示
var result = {
isCorrect: true,
type: "modal",
msg: "请输入",
code: "",
id: ''
};
if ((value == '-1' || value == '' || value == null || value == undefined) && (value != '0')) {//不为空
result.isCorrect = false;
}
return result;
},
};
module.exports = CentralValidate;