Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>jQuery Form Validation</title>
- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
- <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
- <script>
- $.validator.setDefaults({
- submitHandler: function() {alert("submitted!");}
- });
- $(document).ready(function() {
- $("#signupForm").validate({
- rules:{
- name:"required",
- phone:{required: true, rangelength: [10, 10], digits: true},
- username:{required: true, minlength: 2},
- password:{required: true, minlength: 5},
- email:{required: true, email: true},
- agree:"required"
- },
- messages:{
- name:"<b>Please enter your name</b>",
- phone:{required:"<b>Please enter a phone no.</b>", rangelength: "<b>Your phone no. must consist of 10 digits</b>", digits: "<b>Enter only digits</b>"},
- username:{required: "<b>Please enter a username</b>", minlength: "<b>Your username must consist of at least 2 characters</b>"},
- password:{required: "<b>Please provide a password</b>", minlength: "<b>Your password must be at least 5 characters long</b>"},
- email:"<b>Please enter a valid email address</b>",
- agree:"<b>Please accept our policy</b>"
- }
- });
- });
- </script>
- </head>
- <body>
- <form id="signupForm">
- <fieldset><legend>Validating a form using jQuery Validation Plugin</legend>
- <p><label>Name</label><input name="name" type="text" /></p>
- <p><label>Phone</label><input name="phone" type="text" /></p>
- <p><label>Username</label><input name="username" type="text" /></p>
- <p><label>Password</label><input name="password" type="password" /></p>
- <p><label>Email</label><input name="email" type="email" /></p>
- <p><label>Do you agree with our Terms and Conditions?</label><input type="checkbox" name="agree" /></p>
- <p><input type="submit" value="Submit"/></p>
- </fieldset>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement