- Online Demo 1
- Local Downloads
Original link: http://www.gbtags.com/gb/share/5749.htm
Recently in the user login, registration, and User Center ... Then in the MU class network jquery.validate need place, according to their own needs to make the details of the changes, it is important to style it.
The first time to publish these, not good to say don't mind, start. First of all:
- $("#form"). Validate({
- //Edit in this area
- });
Validation often requires debugging, and the framework includes a method, as follows:
- Debug:True, //debug mode (not committed)
To an instance, HTML:
- <div Class="Form-group">
- <label for ="username"> user name:</label>
- <input type="text" name="username" id="username" placeholder="Please enter user name" />
- </div>
Set validation with the Rules method, then the requirement is: required, length between 3-10:
- $(document). Ready(function() {
- $("#form"). Validate({
- Debug:True, //debug mode
- Rules: {
- Username: {
- Required:true, //enable required fields
- Rangelength: [3,] //Please enter a value between 3 and 10 bits
- };
- };
- });
- });
My understanding is that you get the name value and type types to validate. Let's re-enter the password:
Html:
- <div Class="Form-group">
- <label for ="Confirm-password"> Confirm password:</label>
- <input type="password" name= "Confirm-password" id=" Confirm-password " placeholder=" Please enter your password again " />
- </div>
- Js:
- Password: {
- Required:true,
- Rangelength: [6,]
- },
- "Confirm-password": {
- Equalto:"#password" //must have the same password
- }
If you want to customize the prompt message, then use the messages method:
- Messages: {
- Username: {
- Required:"user name cannot be left blank", //user name must fill in the prompt
- Rangelength:"Please check if the length of the number you entered is between 2 and 10" //user name length hint
- }
Let's talk about style, when the input box is wrong, class becomes error, and when the input box is correct, class class becomes valid, so different color border is added:
- . form-group input. Error{
- Border-color: #E74C3C;
- }
- . form-group input. Valid {
- Border-color: #55D98D;
- }
The message of the prompt? When the input box prompts an error, the note pops up, the class name is error, the input box prompt is correct, the note is hidden, and the class name success is added, then:
- . form-group span. Error{
- Color: #E74C3C;
- }
- . form-group span. Success{
- Display: none;
- }
In fact, there are many ways, such as: Groups, errorplacement ... Basically can meet the requirements of form verification, demo there is a demo, see it.
Original link: http://www.gbtags.com/gb/share/5749.htm
Jquery.validate.js "Simple and practical form validation framework"