Advertisement
panwars

jQueryFormValidationPost2.2

Aug 2nd, 2013
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2. $("#userForm").validate({
  3.  
  4. //rules basically define rules on your input fields.You can put different rules based on your requirement and availability(which you can check in jQuery validation documentation).
  5.  
  6. rules:{
  7. userName:"required",
  8. password:"required",
  9. confirmPassword:"required",
  10. dateOfBirth:"required",
  11. gender:"required"
  12. },
  13.  
  14. //messages are map to inputs and will be present if user violates any of the rule.
  15.  
  16. messages:{
  17. userName : "UserName is a required field.",
  18. password : "Password is a required field.",
  19. confirmPassword : "Please enter same as confirmPassword.",
  20. dateOfBirth : "Date of Birth is a required field.",
  21. gender : "Gender is a required field."
  22. },
  23.  
  24. //submitHandler handles task which we can perform after successful validation.
  25. Like below after successful validation I'm adding action attribute to my form and submitting it.
  26.  
  27. submitHandler:function(){
  28. $('#userForm').attr( { action: $('#actionMainURL').val() } );  
  29. $('#userForm').submit();
  30. }
  31. });
  32.  
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement