Use jquery to write your form validation

Source: Internet
Author: User

It's a good feeling to see the sharp jquery these days. Especially jquery's powerful selector. Use jquery today to write a small case of your own form verification. While consolidating the next jquery. First, the code, of course, is only a small case.

Ideas:

1, <input type= "text" validate= "date" id= "date"/> Here Validate: is we need to verify the type (belongs to the date type), here you can also define yourself. The id attribute is needless to say. <input type= "text" validate= "Notstringnull" id= "notstring"/>

2. var arrayinput = jQuery (' #FormData input ');//Gets the input tag from the form so that all the input tags under the form form can be found

3, iterate array, get Validate property value, see if need to verify, here I use case match

4, using regular expressions to judge or other parties to verify the value of the change is legitimate
5. Use array to store the result and the ID of the corresponding element
6, traversal array, if the value is judged false, then the corresponding color set corresponding to the color of the CSS value, prompting the user.
7. Return the result of validation




    

<! DOCTYPE html>

Verify that the result is false

Verify that the result is false

Verify that the result is true

Use jquery to write your form validation

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.