$ (function () {///determine if integer value equals 0 jQuery.validator.addMethod ("Isinteqzero", function (value, Element) {Valu E = parseint (value); return this.optional (Element) | | Value = = 0; }, "Integer must be 0"); Determines whether the integer value is greater than 0 jQuery.validator.addMethod ("Isintgtzero", function (value, Element) {value = parseint (value); return this.optional (Element) | | Value > 0; }, "Integer must be greater than 0"); Determines whether the integer value is greater than or equal to 0 jQuery.validator.addMethod ("Isintgtezero", function (value, Element) {value = parseint (val UE); return this.optional (Element) | | Value >= 0; }, "Integer must be greater than or equal to 0"); Determines whether the integer value is not equal to 0 jQuery.validator.addMethod ("Isintneqzero", function (value, Element) {value = parseint (valu e); return this.optional (Element) | | Value! = 0; }, "Integer must not equal 0"); Determines whether the integer value is less than 0 jQuery.validator.addMethod ("Isintltzero", function (value, Element) {value = parseint (value) ; return this.optional (Element) | | Value < 0;}, "Integer must be less than 0"); Determines whether the integer value is less than or equal to 0 jQuery.validator.addMethod ("Isintltezero", function (value, Element) {value = parseint (VA Lue); return this.optional (Element) | | Value <= 0; }, "Integer must be less than or equal to 0"); Determines whether the floating-point value equals 0 jQuery.validator.addMethod ("Isfloateqzero", function (value, Element) {value = parsefloat (V Alue); return this.optional (Element) | | Value = = 0; }, "floating-point number must be 0"); Determines whether the floating-point value is greater than 0 jQuery.validator.addMethod ("Isfloatgtzero", function (value, Element) {value = parsefloat (VA Lue); return this.optional (Element) | | Value > 0; }, "floating point must be greater than 0"); Determines whether the floating-point value is greater than or equal to 0 jQuery.validator.addMethod ("Isfloatgtezero", function (value, Element) {value = Parsefloa t (value); return this.optional (Element) | | Value >= 0; }, "floating point must be greater than or equal to 0"); Determines whether the floating-point value is not equal to 0 jQuery.validator.addMethod ("Isfloatneqzero", function (value, Element) {value = parsefloat (value); Return This.optionaL (Element) | | Value! = 0; }, "floating-point number must not be equal to 0"); Determines whether the floating-point value is less than 0 jQuery.validator.addMethod ("Isfloatltzero", function (value, Element) {value = parsefloat (V Alue); return this.optional (Element) | | Value < 0; }, "floating point must be less than 0"); Determines whether the floating-point value is less than or equal to 0 jQuery.validator.addMethod ("Isfloatltezero", function (value, Element) {value = Parseflo at (value); return this.optional (Element) | | Value <= 0; }, "floating point number must be less than or equal to 0"); Judging floating-point JQuery.validator.addMethod ("Isfloat", function (value, Element) {return this.optional (element) | |/^ [-\+]?\d+ (\.\d+)? $/.test (value); }, "can only contain numbers, decimal places and other characters"); Match integer JQuery.validator.addMethod ("Isinteger", function (value, Element) {return this.optional (element) | | parseint (value) = = value; }, "Please enter an integer"); Determine the numeric type, including integer and floating-point number JQuery.validator.addMethod ("Isnumber", function (value, Element) {return this.optional (eleme NT) | | /^[-\+]?\d+$/.test (value) | | /^[-\+]?\d+ (\.\d+) $/.Test (value); }, "match numeric types, including integers and floating-point numbers"); only input [0-9] numeric JQuery.validator.addMethod ("Isdigits", function (value, Element) {return this.optional (Element) || /^\d+$/.test (value); }, "only 0-9 digits can be entered"); Judgment Chinese character JQuery.validator.addMethod ("Ischinese", function (value, Element) {return this.optional (element) | | /^[\u0391-\uffe5]+$/.test (value); }, "can only contain Chinese characters. "); Judging English characters JQuery.validator.addMethod ("Isenglish", function (value, Element) {return this.optional (element) | | /^[a-za-z]+$/.test (value); }, "can only contain English characters." "); Mobile number verification JQuery.validator.addMethod ("IsMobile", function (value, Element) {var length = Value.length; return this.optional (Element) | | (length = = &&/^ ((13[0-9]{1}) | ( 15[0-9]{1}) | (18[0-9]{1})) +\D{8}) $/.test (value)); }, "Please fill in your mobile phone number correctly." "); Phone number verification JQuery.validator.addMethod ("Isphone", function (value, Element) {var Tel =/^ (\d{3,4}-?)? \d{7,9}$/g; return this.optional (Element) || (Tel.test (value)); }, "Please fill in your phone number correctly." "); Contact Phone (Mobile/Phone) Verify JQuery.validator.addMethod ("Istel", function (value, Element) {var length = Value.length; var mobile =/^ ((13[0-9]{1}) | ( 15[0-9]{1}) | (18[0-9]{1})) +\D{8}) $/; var tel =/^ (\d{3,4}-?)? \d{7,9}$/g; return this.optional (Element) | | Tel.test (value) | | (length = = && Mobile.test (value)); }, "Please fill in your contact information correctly"); Match QQ JQuery.validator.addMethod ("isqq", function (value, Element) {var QQ =/^[1-9]\d{4,12}$/; return this.optional (Element) | | Qq.test (value); }, "Please enter the correct QQ number"); ZIP Code verification JQuery.validator.addMethod ("Iszipcode", function (value, Element) {var zip =/^[0-9]{6}$/; return this.optional (Element) | | (Zip.test (value)); }, "Please fill in your zip code correctly." "); Match the password, beginning with a letter, with a length of 6-12 and only characters, numbers, and underscores. JQuery.validator.addMethod ("Ispwd", function (value, Element) {return this.optional (element) | |/^[a-za-z]\\w{6,12 }$/.test (value); }, "starts with a letter, is between 6-12 and can contain only characters, numbers, and underscores. "); ID Number Verification JQuery.validator.addMethod ("Isidcardno", function (value, Element) {//var Idcard =/^ (\d{6}) ()? ( \D{4}) (\d{2}) (\d{2}) (\d{3}) (\w) $/; return this.optional (Element) | | Isidcardno (value); }, "Please enter the correct ID number." "); IP Address Verification jQuery.validator.addMethod ("IP", function (value, Element) {return this.optional (element) | |/^ ([ 1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) \.) ([1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) \.) {2} ([1-9]| ([1-9]\d) | (1\d\d) | (2 ([0-4]\d|5[0-5]))) $/.test (value); }, "Please fill in the correct IP address." "); Character validation can only contain characters such as Chinese, English, numerals, underscores, and so on. JQuery.validator.addMethod ("Stringcheck", function (value, Element) {return this.optional (element) | |/^[a-za-z0-9 \u4e00-\u9fa5-_]+$/.test (value); }, "can only contain Chinese, English, numerals, underscores and other characters"); Match 中文版 JQuery.validator.addMethod ("Isenglish", function (value, Element) {return this.optional (Element) || /^[a-za-z]+$/.test (value); }, "Please enter English"); Match Chinese characters JQuery.validator.addMethod ("Ischinese", function (value, Element) {return this.optional (element) | |/^[\u4e00-\u 9fa5]+$/.test (value); }, "Please enter Chinese characters"); Match Chinese (including kanji and characters) JQuery.validator.addMethod ("Ischinesechar", function (value, Element) {return this.optional (E Lement) | | /^[\u0391-\uffe5]+$/.test (value); }, "Match Chinese (including Kanji and characters)"); Determines whether a valid character (a-za-z0-9-_) JQuery.validator.addMethod ("Isrightfulstring", function (value, Element) {return this . Optional (Element) | | /^[a-za-z0-9_-]+$/.test (value); }, "Judging whether it is a valid character (a-za-z0-9-_)"); Determines whether to include special characters in both English and Chinese, except for the "-_" character in English JQuery.validator.addMethod ("Iscontainsspecialchar", function (value, Element) {var Reg = RegExp (/[(\) (\ ') (\~) (\!) (\@) (\#) (\$) (\%) (\^) (\&) (\*) (\ () (\)) (\+) (\=) (\|) (\{)(\}) (\‘) (\:)(\;)(\‘)(‘,)(\[)(\])(\.) (\<) (\>) (\/) (\?) (\~) (\! ) (\@) (\#) (\¥) (\%) (\ ...) (\&) (\*) (\() (\)) (\—) (\+) (\|) (\{)(\}) (\【) (\】) (\‘) (\;) (\:) (\”) (\“) (\’) (\。 )(\,)(\、)(\? )]+/); return this.optional (Element) | | !Reg.test (value); }, "contains Chinese and English special characters"); Authentication rules for identity card number function Isidcardno (num) {//if (IsNaN (num)) {alert ("input is not a number! "); return false;} var len = num.length, re; if (len = =) Re = new RegExp (/^ (\d{6}) ()? ( \D{2}) (\d{2}) (\d{2}) (\d{2}) (\w) $/); else if (len = =) Re = new RegExp (/^ (\d{6}) ()? ( \D{4}) (\d{2}) (\d{2}) (\d{3}) (\w) $/); else {//alert ("the number of digits entered is incorrect. "); return false; } var a = Num.match (re); if (A! = null) {if (len = =) {var D = new Date ("+" + a[3] + "/" + a[4] + "/" + a[5]); var B = d.getyear () = = A[3] && (D.getmonth () + 1) = = A[4] && d.getdate () = = A[5]; } else {var D = new Date (a[3] + "/" + a[4] + "/" + a[5]); var B = d.getfullyear () = = A[3] && (D.getmonth () + 1) = = A[4] && d.getdate () = = A[5]; } if (! B) {//alert ("outputID number "+ a[0] +" in the wrong date of birth. "); return false; }} if (!re.test (num)) {//alert ("the last digit of the identity card can only be numbers and letters. "); return false; } return true; }}); Jquery.extend (JQuery.validator.messages, {required: "required field", Remote: "Please fix this field", Email: "Please enter the correct format of e-mail", url: "Please enter a valid URL", Date: "Please enter a valid date", Dateiso: "Please enter a valid date (ISO).", Number: "Please enter valid numbers", digits: "Enter only integers", creditcard : "Please enter a valid credit card number", Equalto: "Please enter the same value again", Accept: "Please enter a string with a valid suffix name", Maxlength:jQuery.validator.format ("Please enter a length of up to {0 }, Minlength:jQuery.validator.format ("Please enter a string with a minimum length of {0}"), Rangelength:jQuery.validator.format ("Enter a length between The string between {0} and {1} "), Range:jQuery.validator.format (" Enter a value between {0} and {1} "), Max:jQuery.validator.format (" Please enter a maximum is the value of {0} "), Min:jQuery.validator.format (" Enter a value of minimum {0} ")});
$ ("#form_AddMember"). Validate ({rules: {add_name: {required:true, maxlength:30}, Add_username: {required:true, maxlength:30}//,add_worknumber: {required:true, maxlength:30} , add_workposition: {required:true, maxlength:30}, Add_password1: {required:true, MA Xlength:32, Minlength:6, checkpassword:true}, Add_password2: {required:true, maxlength:32, Minlengt H:6, Equalto: ' #Add_Password1 ', Checkpassword:true}}, messages: {add_name: {req uired: "Please enter first name", MaxLength: "No more than 30 bits"}, Add_username: {required: "Please enter username", MaxLength: "No more than 30 bits"} , Add_worknumber: {required: "Please enter work number", MaxLength: "Cannot exceed 30 bits"}//, Add_workposition: {required: "please Enter position ", MaxLength:" Cannot exceed 30 bits "}, Add_password1: {required:" Password cannot be empty ", maxlength:" Length up to 32 bits ", minlength:" Minimum length 6-bit "}, ADd_password2: {required: "Password cannot be empty", maxlength: "Up to 32 bits in length", minlength: "Minimum length 6 bits", Equalto: "Two times password not entered"}}} );
The code that uses JS to actively trigger validate validation is
$ ("#form_AddMember"). Validate ();//Active Authentication if (!$ ("#form_AddMember"). Valid ()) {return;}
Jquery.validate.js Common extension functions