Added custom validation rules for dwz Data Validation

Source: Internet
Author: User

When I was writing data validation, I forgot to write the new custom validation in dwz. Just find dwz. min. if ($. validator) {location, write your own regular expression validation in it. I have added two regular expressions. The Mac or MMS code is as follows:

If ($. validator) {$. validator. addmethod ("Alphanumeric", function (value, element) {return this. optional (element) |/^ \ W + $/I. test (value) ;}, "letters, numbers or underscores only please"); $. validator. addmethod ("lettersonly", function (value, element) {return this. optional (element) |/^ [A-Z] + $/I. test (value) ;}, "letters only please"); $. validator. addmethod ("phone", function (value, element) {return this. optional (element) |/^ [0-9 \ (\)] {7, 30} $ /. test (value) ;}, "Please specify a valid phone number"); $. validator. addmethod ("Mac", function (value, element) {return this. optional (element) |/^ ([a-fA-F0-9] {2}: [a-fA-F0-9] {2}: [a-fA-F0-9] {2}: [a-fA-F0-9] {2 }: [a-fA-F0-9] {2}: [a-fA-F0-9] {2 }) | ([a-fA-F0-9] {2}-[a-fA-F0-9] {2}-[a-fA-F0-9] {2}-[a-fA-F0-9] {2}-[a-fA-F0-9] {2}-[a-fA-F0-9] {2 }) $ /. test (value) ;}, "Please specify a valid phone number"); $. validator. addmethod ("MMS", function (value, element) {return this. optional (element) |/^ MMS $ /. test (value) ;}, "Please MMS ");


 

Add class = "MMS" or class = "Mac" to the HTML tag to be used.

The Code is as follows:

<input type="text" name="aaa" class="required mac"/>


The first class is non-empty, and the second is self-written validation.

Added custom validation rules for dwz Data 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.