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
- <Script type = "text/javascript" src = "XXXXX/js/jquery. validate. js"> </script>
The following is a reference to verify the specific usage:
JavaScript code
- <Script type = "text/javascript">
- $ (Document). ready (function (){
- $ ("# Creator_2"). validate ({
- Rules :{
- Province :{
- Required: true
- },
- City :{
- Required: true
- },
- Area :{
- Required: true
- },
- S_name :{
- Required: true,
- Minlength: 2,
- Maxlength: 10
- },
- S_email :{
- Required: true,
- Email: true,
- Maxlength: 30
- },
- S_address :{
- Required: true,
- Minlength: 5,
- Maxlength: 100
- },
- S_tel :{
- Required: true,
- Minlength: 7,
- Maxlength: 15
- }
- },
- Messages :{
- Province :{
- Required: "select Province"
- },
- City :{
- Required: "select City"
- },
- Area :{
- Required: "select a region"
- },
- S_name :{
- Required: "Please enter your name ",
- Minlength: "The name must be at least 2 characters ",
- Maxlength: "The name cannot exceed 10 characters"
- },
- S_email :{
- Required: "Enter your email address ",
- Email: "enter the correct format ",
- Maxlength: "A mailbox can contain up to 30 characters"
- },
- S_address :{
- Required: "Enter the shipping address ",
- Minlength: "The shipping address must contain at least five characters ",
- Maxlength: "The shipping address can contain a maximum of 100 characters"
- },
- S_tel :{
- Required: "Enter the phone number ",
- Minlength: "The telephone number must be at least five characters ",
- Maxlength: "The maximum number of phone numbers is 13 characters"
- }
- }
- });
- });
- </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
- <Input name = "s_email" id = "s_email" type = "text" class = "input required"/>