Encapsulating custom Validation Methods-validate-methods.js

Source: Internet
Author: User

$ (function () {///determine if integer value equals 0 jQuery.validator.addMethod ("Isinteqzero", function (value, Element) {value               =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 (valu               e); 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 (value               ); 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 (val               UE); 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 (VA               Lue); 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 (val               UE); 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=parsefloat               (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 (VA               Lue); 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=parsefloa               t (value); return this.optional (Element) | |           value<=0;          }, "floating point number must be less than or equal to 0"); Determines the float type 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 the integer JQuery.validator.addMethod ("Isinteger", function (value, Element) {return this.optional (ele MENT) | |           (/^[-\+]?\d+$/.test (value) && parseint (value) >=0);           }, "Match integer"); Determine numeric types, including integers and floating-point numbers jQuery.validator.addMethod ("Isnumber", function (value, Element) {return This.optiona L (Element) | | /^[-\+]?\d+$/.test (value) | |           /^[-\+]?\d+ (\.\d+) $/.test (value);          }, "match numeric types, including integers and floating-point numbers"); only input [0-9] digital JQuery.validator.addMethod ("Isdigits", function (value, Element) {return this.optional (el Ement) | |           /^\d+$/.test (value);          }, "only 0-9 digits can be entered"); Judgment Chinese character JQuery.validator.addMethod ("Ischinese", function (value, Element) {return this.optional (eleme NT) | |           /^[\u0391-\uffe5]+$/.test (value); }, "can only contain Chinese characters.        "); Judge the English character JQuery.validator.addMethod ("Isenglish", function (value, Element) {return this.optional (eleme NT) | |           /^[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==11 && mobile.test (value));       }, "Please fill in your contact information correctly"); Match QQ JQuery.validator.addMethod ("isqq", function (value, Element) {return this.optional (element ) ||           /^[1-9]\d{4,12}$/;         }, "matching QQ"); 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 groundAccess.       ");        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 (E Lement) | |           /^[a-za-z]+$/.test (value);           }, "match 中文版"); Match Kanji JQuery.validator.addMethod ("Ischinese", function (value, Element) {return this.optional (elemen T) | |           /^[\u4e00-\u9fa5]+$/.test (value);           }, "matching Chinese characters"); Match Chinese (including kanji and characters) JQuery.validator.addMethod ("Ischinesechar", function (value, Element) {return this.opt ional (Element) | |           /^[\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) {Retu RN This.optionaL (Element) | |           /^[a-za-z0-9_-]+$/.test (value);           }, "Judging whether it is a valid character (a-za-z0-9-_)"); Determines whether a special character in English or Chinese is included, except for the "-_" character in English JQuery.validator.addMethod ("Iscontainsspecialchar", function (value, Element) {VA R 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==15) {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 ("entered ID number" + a[0] + "The birth date is incorrect.             ");        return false; }} if (!re.test (num)) {//alert ("the last digit of the identity card can only be numbers and letters.            ");        return false;     } return true; } });

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.