Self-organizing jquery. Validate Validation expressions

Source: Internet
Author: User

Self-organizing a few jquery. Validate Verify the Regular:

1. Enter only numbers and letters /^[0-9a-za-z]*$/g

JQuery.validator.addMethod ("Letters", function (value, Element) {    return this.optional (Element) | |/^[0-9a-za-z]* $/g.test (value);}, "Only enter numbers and letters!");

2. The quantity must be a positive integer /^\+?[ 1-9]\d*$/

JQuery.validator.addMethod ("Count", function (value, Element) {    return this.optional (Element) | |/^\+?[ 1-9]\d*$/.test (value);}, "Quantity must be a positive integer!");

3. Only non-negative integer/^ can be entered ([1-9]\d*|[ 0]) $/

function (value, Element) {    returnthis. Optional (Element) | |/^ ([1-9]\d*|[ 0]) $/"can only enter non-negative integers!");

4. date is YYYY-MM-DD format! /^ (\d{4})-(\d{2})-(\d{2}) $/

function (value, Element) {    returnthis. Optional (Element) | |/^ (\D{4})-(\d{2})-(\d{2}) $/  "date is YYYY-MM-DD format!");

5. the temperature is 100.00 to 100.00 /^-? \d| [1-9]\d|100] (\.\d{1,2})? $/

function (value, Element) {    returnthis. Optional (Element) | |/^-? ( \d| [1-9]\d|100] (\.\d{1,2})? $/"Temperature is 100.00 to 100.00");

6. Humidity of 0 to 100.00 /^ (\d|[ 1-9]\d|100) (\.\d{1,2})? $/

function (value, Element) {    returnthis. Optional (Element) | |/^ (\d|[ 1-9]\d|100) (\.\d{1,2})? $/"humidity of 0 to 100.00");

7. Please enter an integer greater than 0 or retain three decimal places

function (value, Element) {    // Enter an integer greater than 0 or leave the three-bit decimal    returnthis. Optional ( Element) | | /(^[1-9]{1}[0-9]*$) | (^[0-9]*\. [0-9] {3}$)/"Invoice amount shall not be less than or equal to 0");

8. Invoice number contains numbers,-,/three characters, no spaces

function (value, Element) {    returnthis. Optional (Element) | |/^[-/0-9]*$/.test (value);} , "Please enter a valid invoice number");



Self-organizing jquery. Validate Validation expressions

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.