Jquery built-in form Verification form usage example

Source: Internet
Author: User

Download a completed jquery validation Library: jquery validation library, decompress it, and put it in the js file folder. On your current page, reference the path of the jquery verification form Library:

For example:

JavaScript code
  1. <Script type = "text/javascript" src = "XXXXX/js/jquery. validate. js"> </script>
  2. The following is a reference to verify the specific usage:

    JavaScript code
    1. <Script type = "text/javascript">
    2. $ (Document). ready (function (){
    3. $ ("# Creator_2"). validate ({
    4. Rules :{
    5. Province :{
    6. Required: true
    7. },
    8. City :{
    9. Required: true
    10. },
    11. Area :{
    12. Required: true
    13. },
    14. S_name :{
    15. Required: true,
    16. Minlength: 2,
    17. Maxlength: 10
    18. },
    19. S_email :{
    20. Required: true,
    21. Email: true,
    22. Maxlength: 30
    23. },
    24. S_address :{
    25. Required: true,
    26. Minlength: 5,
    27. Maxlength: 100
    28. },
    29. S_tel :{
    30. Required: true,
    31. Minlength: 7,
    32. Maxlength: 15
    33. }
    34. },
    35. Messages :{
    36. Province :{
    37. Required: "select Province"
    38. },
    39. City :{
    40. Required: "select City"
    41. },
    42. Area :{
    43. Required: "select a region"
    44. },
    45. S_name :{
    46. Required: "Please enter your name ",
    47. Minlength: "The name must be at least 2 characters ",
    48. Maxlength: "The name cannot exceed 10 characters"
    49. },
    50. S_email :{
    51. Required: "Enter your email address ",
    52. Email: "enter the correct format ",
    53. Maxlength: "A mailbox can contain up to 30 characters"
    54. },
    55. S_address :{
    56. Required: "Enter the shipping address ",
    57. Minlength: "The shipping address must contain at least five characters ",
    58. Maxlength: "The shipping address can contain a maximum of 100 characters"
    59. },
    60. S_tel :{
    61. Required: "Enter the phone number ",
    62. Minlength: "The telephone number must be at least five characters ",
    63. Maxlength: "The maximum number of phone numbers is 13 characters"
    64. }
    65. }
    66. });
    67. });
    68. </Script>

    Note: creator_2 is the form ID, province, and s_email. These are the IDs of the form elements. It is best to give them the same names and ID numbers for convenient operations. The format is as follows:

     

    XML/HTML code
    1. <Input name = "s_email" id = "s_email" type = "text" class = "input required"/>

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.