additional-methods.js 1.95 KB
/*
 * 自己定义扩展验证规则用于表单验证
 * 
 * */

 // 验证是字母, 数字
jQuery.validator.addMethod("isDigitalOrAlph", function (value, element) {
    return this.optional(element) || /^[0-9a-zA-Z]+$/.test(value);
}, "请填写正确的字母或者数字");

 // 验证是邮编
jQuery.validator.addMethod("isZip", function (value, element) {
    var zip =  /^[1-9]\d{5}$/;
    return this.optional(element) || zip.test(value);
}, "请填写正确的邮政编码");

//验证是否是企业
jQuery.validator.addMethod("isSupplier", function (value, element) {
	return this.optional(element) || /^[\u4E00-\u9FA5]+$/.test(value);
}, "请填写正确的公司名称");

//验证电话号码
jQuery.validator.addMethod("isPhoneno", function (value, element) {
    //var phone = /((^\d{11}$)|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
    var phone = /^((\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})(\d{7,8}))$/;
    return this.optional(element) || phone.test(value);
}, "请填写正确的电话号码");

 // 护照号格式验证
jQuery.validator.addMethod("isPassport", function(value,element) {
  var passport = /^(P\d{7}|G\d{8}|S\d{7,8}|D\d+|1[4,5]\d{7})$/;
      return this.optional(element) || (passport.test(value));
 }, "请填写正确的护照号");

//验证钱
jQuery.validator.addMethod("isMoney", function (value, element) {
    var money = /^\d+(\.\d{1,2})?$/;
    return this.optional(element) || (money.test(value));
}, "请输入正确的金额");


//验证是否包含特殊字符
jQuery.validator.addMethod("specialStrCheck", function (value, element) {
    var regExp = new RegExp("[`~!@%#$^&*()=|{}':;',\\[\\]<>/?/\]\\.;:%……+ ¥()【】‘”“'.。,、?1234567890-=_+~?!@#$%^&*)]"); 
    return this.optional(element) || !regExp.test(value);
}, "输入不正确,包含特殊字符或者圆角字符");