Recently in the end of the interface, has been written form validation! have been writing form validation! Found jquery-validate is really useful ah, today summed up some:
(1) Required:true must lose field
(2) Remote: "check.php" using Ajax method call check.php Validate input value
(3) Email:true must enter the correct format of e-mail
(4) Url:true must enter the correct format of the URL
(5) Date:true must enter the correct format date
(6) Dateiso:true must enter the correct format for the date (ISO), for example: 2009-06-23, 1998/01/22 only verify the format, do not verify the validity
(7) Number:true must enter a valid number (negative, fractional)
(8) Digits:true must enter an integer
(9) CreditCard: Must enter a valid credit card number
Equalto: The "#field" input value must be the same as #field
(one) Accept: Enter a string with a valid suffix (the suffix of the uploaded file)
Maxlength:5 input string with a maximum length of 5 (Chinese characters are counted as one character)
(minlength:10) Enter a string with a minimum length of 10 (Chinese characters are counted as one character)
(rangelength:[5,10] Enter a string that must be between 5 and 10 in length) (Chinese characters are counted as one character)
(range:[5,10] Input value must be between 5 and 10
(+) Max:5 input value cannot be greater than 5
(min:10) input value cannot be less than 10
Demo:
The first is to draw the jquery and Jquery.validate class libraries:
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script type= "Text/javascript" src= "Jquery.validate.js" ></script>
In HTML:
<form action= "" method= "Get" id= "form" >
<input type= "text" value= "" name= "UserName"/>
<input type= "Submit" value= "Submission"/>
</form>
Turn on authentication mode in Js/ts
$ ("#form"). Validate ({
Add Validation Rule
Rules: {
username:{
Required:true,
Digits:true,
Username:true,
Rangelength: [5,10]
}
},
Reset Message
messages:{
UserName: {
Required: "Please fill in the user name",
Digits: "Please enter an integer",
Rangelength: "User name must be between 5-10 characters"
}
}
});
Although simple but must be careful, before the messages written in the rules, the results will not come out. So be careful, spur yourself!
About Jquery-validate Validation forms