JQuery Validate validation Framework uses

Source: Internet
Author: User

JQuery validate before using the preparation, need to download the corresponding JS include: 1, Jquery.validate.min.js. 2, Additional-methods.min.js.

Of course an essential JS jquery file.

The introduction of the above JS began to use, JV (jquery validate hereinafter called JV) there are two uses, first look at the first type:

The first is directly in the control using class directly in the way, such as: class= "Email", this method if you want to verify the length, it seems to be ineffective, it may not be studied.

JV's prompt is in English by default, we can use the built-in method to replace the cue with what we want.

Note: You must specify the form to validate before you use it. Look at the code:

The above code is the way to validate directly with the built-in validation method in CALSS.

Take a look at the second type, in JS to verify:

Specifies that validation is successful after committing submithandler:function (form) {form.submit (); },
Control to validate rules: {myname: {required:true}, Email: {required:true, email:true} , Jia: {required:true, byterangelength: [3, 6] } },
Prompt messages: {myname: {required: ' Required '}, Email: {Required: "required", email: "E-mail format is not correct" } } }); Add custom Validation JQuery.validator.addMethod ("Byterangelength", function (value, element, param) {var length = Value.length; for (var i = 0; i < value.length; i++) {if (Value.charcodeat (i) > 127) { length++; }} return This.optional (Element) | | (length >= param[0] && length <= param[1]); }, $.validator.format ("Make sure the value entered is between {0}-{1} bytes (2 bytes in one text)");
Define the prompt $.extend ($.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: "Can only enter integers", CREDITC ARD: "Please enter a valid credit card number", Equalto: "Please enter the same value again", Accept: "Please enter a string with legal suffix name", maxlength: $.validator.format ("Please enter a string with a maximum length of {0}"), MinLength: $.validator.format ("Enter a string with a minimum length of {0}"), Rangelength: $.validator.format ("Please enter a string between {0} and {1}"), Range: $.validator.format ("Please enter a value between {0} and {1}, Max: $.validator.format ("Enter a value of {0} max"), Min: $.validator.format ("Enter a minimum of Value of {0})}); }); </script>

The above code is in JS to verify.

The three parameters for adding custom validation are: The validation name, the function to execute (there are also three parameters for the function to be executed: Val,element,param), the value to return (can be formatted).

Simple custom validation to add:

$.validator.addmethod (            "Lths", function (val, element, PMS) {                if (Val.length > Pms.length) {                    return true;                }                else {                    return false;                }            , $.validator.format ("must be greater than {0} bytes"));//When called in rules Lths[6]

  

JQuery Validate validation Framework uses

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.