Jquery extension validate-1 basic usage

Source: Internet
Author: User

Validate is the jquery extension plug-in used for client verification of the B/S structure. Two JS files must be referenced during use, which are:
<SCRIPT src = "../contents/JS/jquery-1.5.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "../contents/JS/jquery. Validate. Min. js" type = "text/JavaScript"> </SCRIPT>

1. Basic usage: set verification rules through styles

< Script Type = " Text/JavaScript " >
$ ( Function () {$ ( " # Signupform " ). Validate ();}); // Verify the selected form
< / SCRIPT>

< P >
< Label For = " Email " > Email < / Label>
< Input ID = " Email " Name = " Email " Class = " Required email "   / >
<! -- This indicates that the email address is required and correct. -->
< / P>
< P >
< Label For = " Txtage " > Age < / Label>
< Input ID = " Txtage " Name = " Txtage " Min = " 18 " Max = " 45 "   / >
<! -- Only 18 - Between 45 -->
< / P>

When a form is submitted, an error occurs if no email is entered or the email is incorrect, as shown below:

 

 

The default prompt after the text box indicates that jquery can be modified. validate. min. JS. Search for and replace the style with Chinese. The style can be changed through the CSS class style, as shown in. required ,. email, etc. Of course, the class here can be separated by spaces among one or more items. The syntax format is the same as that of CSS. The options are as follows:

 

(1) required: required field for true
(2) Remote: "check. php" uses ajax to call check. php to verify the input value.
(3) Email: true: You must enter an email in the correct format.
(4) URL: True must enter the URL in the correct format
(5) Date: True must be a date in the correct format
(6) dateiso: true: the date (ISO) in the correct format must be entered. For example, 2009-06-23,1998/01/22: only the format is verified and the validity is not verified.
(7) number: true: a valid number (negative number, decimal number) must be entered)
(8) digits: True must be an integer.
(9) creditcard: a valid credit card number must be entered.
(10) must to: "# field" the input value must be the same as # Field
(11) accept: enter a string with a valid suffix (the suffix of the uploaded file)
(12) maxlength: A string with a maximum length of 5 characters)
(13) minlength: 10 string with a minimum input length of 10 (one character for Chinese characters)
(14) rangelength: [5, 10] The input length must be a string between 5 and 10. ") (a Chinese character is a single character)
(15) range: [5, 10] The input value must be between 5 and 10.
(16) max: 5 input value cannot be greater than 5
(17) min: 10 input value cannot be less than 10

 

Source code download

 

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.