JS validation control jquery Validate

Source: Internet
Author: User

The JQuery Validate plugin provides a powerful validation feature for forms, making it easier to validate client forms, while providing a number of customization options to meet the needs of your application. The plugin bundles a set of useful validation methods, including URL and email validation, and provides an API to write user-defined methods.

The implementation steps are as follows:

Step1: Add a form label to the body tag

  1. <form id= "Login_form" action= "login.action" method= "POST" >
  2. <table cellpadding= "0" cellspacing= "0" border= "0" class= "form_table" >
  3. <tr>
  4. <TD valign= "Middle" align= "right" >
  5. Email:
  6. </td>
  7. <TD valign= "Middle" align= "left" >
  8. <input type= "text" class= "Inputgri" name= "email"/>
  9. <span style= "color:red" >${msg}</span>
  10. </td>
  11. </tr>
  12. <tr>
  13. <TD valign= "Middle" align= "right" >
  14. Password:
  15. </td>
  16. <TD valign= "Middle" align= "left" >
  17. <input type= "Password" class= "Inputgri" name= "password"/>
  18. </td>
  19. </tr>
  20. </table>
  21. <p>
  22. <input type= "Submit" class= "button" value= "Login?"/>
  23. <a href= "register.jsp" > not registered </a>
  24. </p>
  25. </form>

Step2: Import Validate plugin js file

    1. <script type= "Text/javascript" src= "Js/jquery.js" ></script>
    2. <script type= "Text/javascript" src= "Js/jquery.validate.min.js" ></script>
    3. <script type= "Text/javascript" src= "Js/messages_cn.js" ></script>

Step3: Write JS code

  1. <script>
  2. $ (document). Ready (function () {
  3. $ ("#login_form"). Validate ({
  4. Rules: {
  5. Email: {required:true, email:true},
  6. Password:{required:true,minlength:6,maxlength:16},
  7. },
  8. Messages: {
  9. Email: {Required: "Need to enter e-mail address", email: "E-mail format is incorrect"},
  10. Password: {required: "Need to enter password", minlength: "Password length between 6-16 characters", maxlength: "Password length between 6-16 characters"},
  11. }
  12. });
  13. });
  14. </script>

Reference Link: http://www.w3cschool.cc/jquery/jquery-plugin-validate.html

Click to download the source code

JS validation control jquery Validate

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.