Jquery.validate Application and expansion

Source: Internet
Author: User
Tags add time

First, the use of

Default validation rules

(1), Required:TrueMust lose field (2), Remote:"remote-valid.jsp"Calling remote-using AJAX methodsvalid.jsp Validate input values (3), Email:TrueYou must enter an email in the correct format (4), URL:TrueYou must enter a URL in the correct format (5), Date:TrueMust enter the correct format of the date, date check IE6 error, use caution (6), Dateiso:True must enter the correct format for the date (ISO), for example:2009-06-23,1998/21m22Validates the format only, does not validate the validity (7), Number:TrueYou must enter a valid number (negative, fractional) (8), digits:TrueYou must enter an integer (9), CreditCard:TrueYou must enter a valid credit card number (10), Equalto:"#password"The input value must be the same as #password (11), Accept: Enter a string with a legal suffix (the suffix of the upload file) (12), MaxLength:5Enter a string with a maximum length of 5 (Chinese characters are counted as one character) (13 ", Minlength:1014), Rangelength:[5,10] The input length must be between 5 and 10  "" (Chinese characters are counted as one character) (15), Range:[5,10 "input value must be between 5 and 1016), Max:517), Min:              

Original: http://www.cnblogs.com/linjiqin/p/3431835.html (recommended-complete)

Asynchronous validation

Remote:url
Using AJAX to authenticate, the default is to submit the current validated value to the remote address, if you need to commit additional values, you can use the data option

The remote address can only output "true" or "false" and cannot have additional output.

Example one: Remote:"check-email.php"Example two: remote: {URL:"check-email.php//< Span style= "color: #008000;" > spooler type:  "post", Span style= "color: #008000;" >// data sending method DataType:  "// Accept data format: { // username: function () {return $ ( #username  "). val ();}}       

MVC background

[HttpPost] Public ActionResult Hasaccount (string account ) {     return Json (!  AccountRule.Instance.HasAccount (account));//If there are accounts, return false, not present returns true}    

Second, expand

Add a Jquery.validate.ext.js

/** Verification Extension **///Jquery.validator Add Time verification jQuery.validator.addMethod ("Timeiso",function(value, Element) {if (This.optional (Element))ReturnTrue;Try{var strarray = Value.split ("");var strdate = Strarray[0].split ("-");var strtime = Strarray[1].split (":");var a =New Date (Strdate[0], (strdate[1]-parseint (1)), strdate[2], strtime[0], strtime[1], strtime[2]);return a.getfullyear () > 0 && a.getmonth () > 0 && a.getday () > 0; }Catch(e) {}ReturnFalse;}, "Please enter the correct time!" ");//Jquery.validator Add account Verification JQuery.validator.addMethod ("Vaccount",function(value, Element) {ReturnThis.optional (Element) | | (/^\w+$/. Test (value);}, "Please enter English, numbers, underline");/** * Verification message Chinese hint **/$.extend ($.validator.messages, {required: "required field", Remote: $.format ("The account already exists! "), Email: "Please enter the correct format of e-mail", url: "Please enter the correct URL", Date: "Please enter the correct date", Dateiso: "Please enter the correctdate (ISO)", Number: "Please enter the correct numbers", digits: "Can only enter integers", CreditCard: " Please enter the correct credit card number ",equalto:" Please enter the same value again ", accept:" Please enter a string with a valid suffix name ", MaxLength: $.validator.format (" character length {0} " ), minlength: $.validator.format ("minimum character length {0}"), Rangelength: $.validator.format ("character length = {0}-{1}"), Range: $.validator.format ("input value is between {0}-{1}"), Max: $.validator.format ("Enter a value of max {0}"), min: $. Validator.format ("Please enter a value of minimum {0}")});             

Third, add remove verification

In a project, you often encounter forms where some fields need to be hidden depending on the condition, and manually adding remove validation is handy.

$ ("#IDName"). Rules ("Remove"true, messages: {required: "Please enter title"}});

Jquery.validate Application and expansion

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.