Jquery-validation of jquery Plugins

Source: Internet
Author: User
Tags valid email address

Equalto Method:

1Equalto:function(value, element, param) {2 3             //Bind to the Blur event of the "the target" order to revalidate whenever the Target field is updated4             vartarget =$ (param);5             if( This. Settings.onfocusout && Target.not (". Validate-equalto-blur"). length) {6Target.addclass ("Validate-equalto-blur"). On ("Blur.validate-equalto",function() {7 $ (Element). valid ();8                 } );9             }Ten             returnValue = =target.val (); One},

URL Validation Method:

1Url:function(value, Element) {2 3             //Copyright (c) 2010-2013 Diego Perini, MIT licensed4             //https://gist.github.com/dperini/7292945             //See also Https://mathiasbynens.be/demo/url-regex6             //modified to allow protocol-relative URLs7             return  This. Optional (Element) | | /^ (?:(?:(?: https?| FTP):)? \/\/) (?: \ S+ (?:: \s*) [email protected])? (?:(?! (?: 10|127) (?:\. \d{1,3}) {3}) (?! (?: 169\.254|192\.168) (?:\. \d{1,3}) {2}) (?! 172\. (?: 1[6-9]|2\d|3[0-1]) (?:\. \d{1,3}) {2}) (?: [1-9]\d?| 1\d\d|2[01]\d|22[0-3]) (?: \. (?: 1?\d{1,2}|2[0-4]\d|25[0-5])) {2} (?:\. (?: [1-9]\d?| 1\D\D|2[0-4]\D|25[0-4]) | (?:(?: [a-z\u00a1-\uffff0-9]-*) *[a-z\u00a1-\uffff0-9]+) (?: \. (?: [a-z\u00a1-\uffff0-9]-*) *[a-z\u00a1-\uffff0-9]+) * (?: \. (?: [A-z\u00a1-\uffff]{2,})). (?:: \d{2,5})? (?: [/?#]\s*)? $/i.test (value);8},

Dates Date Validation method:

1 // http://jqueryvalidation.org/date-method/ 2         function (value, Element) {3             return  This New Date (value). toString ()); 4         },

Decimal digit verification method with decimal number:

1 // http://jqueryvalidation.org/number-method/ 2         function (value, Element) {3             return this. Optional (element) | | /^ (?:-?\d+|-?\d{1,3} (?:, \d{3}) +)? (?:\. \d+)? $/. Test (value); 4         },

Integer validation method:

1 // http://jqueryvalidation.org/digits-method/ 2         function (value, Element) {3             return this. Optional (element) | | /^\d+$/. Test (value); 4         },

Minimum Length verification method:

1 // http://jqueryvalidation.org/minlength-method/ 2         function (value, element, param) {3             var  This . GetLength (value, Element); 4             return this. Optional (element) | | Length >= param; 5         },

Maximum length verification method:

1 // http://jqueryvalidation.org/maxlength-method/ 2         function (value, element, param) {3             var  This . GetLength (value, Element); 4             return this. Optional (element) | | Length <= param; 5         },

Length Range Verification Method:

1 // http://jqueryvalidation.org/rangelength-method/ 2         function (value, element, param) {3             var  This . GetLength (value, Element); 4             return this. Optional (element) | | (length >= param[0] && length <= param[1 ]); 5         },

Minimum value, maximum value, interval value verification method:

1 //http://jqueryvalidation.org/min-method/2Minfunction(value, element, param) {3             return  This. Optional (Element) | | Value >=param;4         },5 6         //http://jqueryvalidation.org/max-method/7Maxfunction(value, element, param) {8             return  This. Optional (Element) | | Value <=param;9         },Ten  One         //http://jqueryvalidation.org/range-method/ ARangefunction(value, element, param) { -             return  This. Optional (Element) | | (Value >= param[0] && value <= param[1 ] ); -},

Two Chinese character validation: Custom method

1JQuery.validator.addMethod ("Byterangelength",function(value, element, param) {2     varLength =value.length;3      for(vari = 0; i < value.length; i++){4         if(Value.charcodeat (i) > 127){5length++;6         }7     }8   return  This. Optional (Element) | | (length >= param[0] && length <= param[1] ); 9}, $.validator.format ("Make sure the value entered is between {0}-{1} bytes (2 bytes in one text)");

Zip Code Validation: custom Methods

1 // ZIP code   Verification 2 function (value, Element) {   3     var tel =/^[0-9]{6}$/; 4     return this. Optional (element) | | (Tel.test (value)); 5 }, "Please fill in your zip code correctly");

To verify the prompt information:

1 messages: {2Required: "This field is required.",3Remote: "Please fix this field.",4Email: "Please enter a valid email address.",5URL: "Please enter a valid URL.",6Date: "Please enter a valid date.",7Dateiso: "Please enter a valid date (ISO).",8Number: "Please enter a valid number.",9Digits: "Please enter only digits.",TenEqualto: "Please enter the same value again.", OneMaxLength: $.validator.format ("Please enter no more than {0} characters." ), AMinLength: $.validator.format ("Please enter at least {0} characters." ), -Rangelength: $.validator.format ("Please enter a value between {0} and {1} characters long." ), -Range: $.validator.format ("Please enter a value between {0} and {1}.") ), theMax: $.validator.format ("Please enter a value of less than or equal to {0}." ), -Min: $.validator.format ("Please enter a value greater than or equal to {0}." ), -Step: $.validator.format ("Please enter a multiple of {0}.") ) -},

Jquery-validation of jquery Plugins

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.