JQuery Form Verification jquery. validator. js

Source: Internet
Author: User

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.

 
 

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.