In front-end development, forms are often created. The essential function is some simple verification before submission, such as non-empty, mobile phone number, and e-mail, here is a jQuery Form Verification plug-in, which is quite useful.
The following is the verification:
The files to be loaded on the page are:
The zh_CN file mainly contains some built-in verification rules. developers can write regular expressions based on their own needs and add the corresponding rule names to the verification rules. Note that, this plugin uses the name attribute of the control to bind verification rules. Therefore, you must add the name attribute to the form control to be verified.
The following is how to use it:
$ ('Form', timely:, theme: "yellow_right_effect", 'birthday': 'required' 'idnum': 'required' 'Cellphone': 'required; mobile '(form ){}
At this point, we also need a button to trigger the submission method:
$ ('Form'). trigger ("validate ");
The above are some simple and necessary applications. Of course, we often need to dynamically change the form structure during development. Newly Added controls need to be added for verification, and hidden controls need to be de-verified, otherwise, you cannot submit it. Therefore, you need to understand the following methods:
$ ('Form '). validator ("setField", name of the newly added element, "required" 'form '). validator ("setField", name of the element to which verification is canceled, "" 'form '). validator ('hidemsg ', name of the element to which verification is canceled );
Of course, you can also add a message to the element: setMsg
For detailed parameters and methods, refer to validator on the official website.