UNPKG

igi_orion_cignacmb

Version:

Censors words out of text

228 lines (220 loc) 11 kB
var CentralValidator = require('./CentralValidator'); var input = $.extend({}, CentralValidator, { validate: function (appntidType,appntidNo,gender,birthday) { //用于验证,如有错误,返回数组,便于前端提示 var that = this; var errors = []; var data = this.checkIcNumber(appntidType,appntidNo,gender,birthday); if(!data.type){ errors.push({type: "modal", msg: data.message, code: ''}) } // avalon.log(that.value + ':执行了validate操作') return errors.length > 0 ? errors : null; }, checkIcNumber: function (appntidType,appntidNo,gender,birthday) { console.log('checkIcNumber_checkIcNumber', appntidType, appntidNo, gender, birthday); var result = { type : true, msg :"" } if (appntidNo == '' || appntidNo == null) { result.msg = '请输入证件号码'; result.type = false; return result } else { //TODO 港澳居住证验证 switch (appntidType) { case "F"://永久居留证 console.log('appntidNo.length', appntidNo.length); if(appntidNo.length != 15){ result.msg = '证件类型为外国人永久居留身份证时,号码长度必须为15位'; result.type = false; return result } break case "H"://户口本 if (appntidNo.length < 18) { result.msg = '证件类型为身份证、户口本时,号码长度必须为18位'; result.type = false; return result } else { if (this.checkIdCard(appntidNo)) { if ((appntidNo.substring(6, 10) + '-' + appntidNo.substring(10, 12) + '-' + appntidNo.substring(12, 14)) == birthday) { if (!this.checkSexAndId(appntidNo, gender)) { result.msg = '证件号码与性别不匹配'; result.type = false; return result } else { return result; } } else { result.msg = '证件号码和出生日期不一致!'; result.type = false; return result } } else { result.msg = '请输入正确的证件号'; result.type = false; return result } } break; case "I"://身份证 if (appntidNo.length < 18) { result.msg = '证件类型为身份证、户口本时,号码长度必须为18位'; result.type = false; return result } else { var reg = /^[A-Za-z0-9]+$/; if (reg.test(appntidNo)){ result.msg = '请输入正确的证件号'; result.type = false; return result } if (this.checkIdCard(appntidNo)) { if ((appntidNo.substring(6, 10) + '-' + appntidNo.substring(10, 12) + '-' + appntidNo.substring(12, 14)) == birthday) { if (!this.checkSexAndId(appntidNo, gender)) { result.msg = '证件号码与性别不匹配'; result.type = false; return result } else { return result; } } else { result.msg = '证件号码和出生日期不一致!'; result.type = false; return result } } else { result.msg = '请输入正确的证件号'; result.type = false; return result } } break; case "L"://临时身份证 if (appntidNo.length < 18) { result.msg = '证件类型为身份证、户口本时,号码长度必须为18位'; result.type = false; return result } else { if (this.checkIdCard(appntidNo)) { if ((appntidNo.substring(6, 10) + '-' + appntidNo.substring(10, 12) + '-' + appntidNo.substring(12, 14)) == birthday) { if (!this.checkSexAndId(appntidNo, gender)) { result.msg = '请输入正确的证件号'; result.type = false; return result } else { return result; } } else { result.msg = '证件号码和出生日期不一致!'; result.type = false; return result } } else { result.msg = '请输入正确的证件号'; result.type = false; return result } } break; case "P"://护照 if (appntidNo.length >= 3) { return result; } else { result.msg = '证件类型为护照时,号码长度不能少于3个字符'; result.type = false; return result } break; case "T"://港澳通行证 if (appntidNo.length <= 20) { return result; } else { result.msg = '证件类型为港澳居民来往内地通行证或台湾居民来往大陆通行证时,不超过20位数字或字母'; result.type = false; return result } break; case "R"://台胞通行证 if (appntidNo.length <= 20) { return result; } else { result.msg = '证件类型为港澳居民来往内地通行证或台湾居民来往大陆通行证时,不超过20位数字或字母'; result.type = false; return result } break; case "G"://港澳台居民居住证 if (appntidNo.length < 18) { result.msg = '证件类型为身份证、户口本时,号码长度必须为18位'; result.type = false; return result } else { var reg = /^[A-Za-z0-9]+$/; if (reg.test(appntidNo)){ result.msg = '请输入正确的证件号'; result.type = false; return result } if(appntidNo.substring(0, 6) != "810000" && appntidNo.substring(0, 6) != "820000" && appntidNo.substring(0, 6) != "830000"){ result.msg = '请输入正确的证件号'; result.type = false; return result } if ((appntidNo.substring(6, 10) + '-' + appntidNo.substring(10, 12) + '-' + appntidNo.substring(12, 14)) == birthday) { if (!this.checkSexAndId(appntidNo, gender)) { result.msg = '请输入正确的证件号'; result.type = false; return result } else { return result; } } else { result.msg = '证件号码和出生日期不一致!'; result.type = false; return result } } break; case "S"://士兵证 if (appntidNo.length >= 10 && appntidNo.length <= 18) { return result; } else { result.msg = '证件类型为军官证或士兵证,号码长度在10-18个字符之间'; result.type = false; return result } break; case "A"://军官证 if (appntidNo.length >= 10 && appntidNo.length <= 18) { return result; } else { result.msg = '证件类型为军官证或士兵证,号码长度在10-18个字符之间'; result.type = false; return result } break; case "B"://婴儿证 if (appntidNo.length >= 3) { return result; } else { result.msg = '证件类型为出生证,号码长度不能少于3个字符'; result.type = false; return result } break; default : if (appntidNo.length >= 1) { return result; } else { result.msg = '请输入正确的证件号'; result.type = false; return result } break; } } }, }); module.exports = input;