JQuery Validate plug-in Implementation form validation _jquery

Source: Internet
Author: User
Tags html tags lowercase strong password

The JQuery Validate plug-in provides a powerful validation feature for forms, making client form validation simpler, while providing a wide range of customization options to meet the needs of the application. The plug-in bundles a set of useful authentication methods, including URL and email authentication, while providing an API for writing user-defined methods. All bundled methods use English as an error message by default and are translated into 37 other languages. More importantly, he was written and maintained by the jquery team, the main developer of the jquery UI team, Jörn Zaefferer. Specifically, we can visit the jquery Validate website and download the latest version of the jquery Validate plugin.
Need to introduce the following JS file

 <script type= "Text/javascript" src= "jquery.min.js" ></script>
 <script type= "Text/javascript" src = "Jquery.validate.min.js" ></script>
 <script type= "Text/javascript" src= "Validate-methods.js" > </script>
 <script type= "Text/javascript" src= "Messages_zh.min.js" ></script>

Validate-methods.js for extended validation rules
Messages_zh.js as a validation hint file

<! DOCTYPE html>  

Browser results:


Default checksum rule

Regular expressions that are commonly used

One, the expression of the checksum number

1 Number: ^[0-9]*$
2 N digits: ^\d{n}$
3 digits of at least n digits: ^\d{n,}$
4 m-n digits: ^\d{m,n}$
Numbers beginning with 50 and not 0: ^ (0|[ 1-9][0-9]*) $
6 non-0 digits with a maximum of two decimal digits: ^ ([1-9][0-9]*) + (. [ 0-9]{1,2})? $
7 positive or negative numbers with 1-2 decimal places: ^ (\-) \d+ (\.\d{1,2})? $
8 positive, negative, and decimal: ^ (\-|\+) \d+ (\.\d+)? $
9 positive real numbers with two decimal places: ^[0-9]+ (. [ 0-9]{2})? $
10 positive real numbers with 1~3 decimal places: ^[0-9]+ (. [ 0-9]{1,3})? $
11 Nonzero positive integers: ^[1-9]\d*$ or ^ ([1-9][0-9]*) {1,3}$ or ^\+? [1-9] [0-9]*$
12 Non-zero Integer: ^\-[1-9][]0-9 "*$ or ^-[1-9]\d*$
13 non-negative integers: ^\d+$ or ^[1-9]\d*|0$
14 Non-positive integers: ^-[1-9]\d*|0$ or ^ (-\d+) | ( 0+)) $
15 non-negative floating-point number: ^\d+ (\.\d+)? $ or ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
16 Non-positive floating-point number: ^ (-\d+ (\.\d+)?) | (0+ (\.0+)) $ or ^ (-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)) |0?\.0+|0$
17 Positive floating-point numbers: ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ or ^ ([0-9]+\.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\. [0-9]+) | ([0-9]*[1-9][0-9]*)] $
18 Negative floating-point number: ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*) $ or ^ (-([0-9]+\.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\. [0-9]+) | ([0-9]*[1-9][0-9]*))] $
19 Floating-point numbers: ^ (-?\d+) (\.\d+)? $ or ^-? ([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0) $

Second, the expression of the checksum character

1 Chinese characters: ^[\u4e00-\u9fa5]{0,}$
2 English and digital: ^[a-za-z0-9]+$ or ^[a-za-z0-9]{4,40}$
3 All characters of length 3-20: ^. {3,20}$
4 string consisting of 26 English letters: ^[a-za-z]+$
5 A string of 26 uppercase letters: ^[a-z]+$
6 string consisting of 26 lowercase English letters: ^[a-z]+$
7 A string consisting of numbers and 26 English letters: ^[a-za-z0-9]+$
8 A string consisting of numbers, 26 English letters, or underscores: ^\w+$ or ^\w{3,20}$
9 Chinese, English, digital include underline: ^[\u4e00-\u9fa5a-za-z0-9_]+$
10 Chinese, English, digital but excluding underline and other symbols: ^[\u4e00-\u9fa5a-za-z0-9]+$ or ^[\u4e00-\u9fa5a-za-z0-9]{2,20}$
11 can be entered containing ^%& ',; =?$\ ' and other characters:[^%& ', =?$\x22]+
12 prohibit the importation of characters containing ~: [^~\x22]+

Third, the special needs of expression

1 Email Address: ^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$
2 Domain name: [a-za-z0-9][-a-za-z0-9]{0,62} (/.[ A-ZA-Z0-9][-A-ZA-Z0-9]{0,62}) +/.?
3 interneturl:[a-za-z]+://[^\s]* or ^http://([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)? $
4 Mobile phone Number: ^ (13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8| 9]|18[0|1|2|3|5|6|7|8| 9]) \d{8}$
5 Telephone numbers ("Xxx-xxxxxxx", "xxxx-xxxxxxxx", "xxx-xxxxxxx", "xxx-xxxxxxxx", "XXXXXXX" and "XXXXXXXX"): ^ (\d{3,4}-) |\d{3.4}-)? \d{7,8}$
6 Domestic telephone number (0511-4405222, 021-87888822): \d{3}-\d{8}|\d{4}-\d{7}
7 ID Number:
15 or 18-bit ID: ^\d{15}|\d{18}$
15-bit ID: ^[1-9]\d{7} ((0\d) | ( 1[0-2])) (([0|1|2]\d) |3[0-1]) \d{3}$
18-bit ID: ^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2])) (([0|1|2]\d) |3[0-1]) \d{4}$
8 Short ID Number (number, letter X end): ^ ([0-9]) {7,18} (x| X)? $ or ^\d{8,18}| [0-9x] {8,18}| [0-9x] {8,18}?$
9 Account number is legal (beginning of letter, allow 5-16 bytes, allow alphanumeric underline): ^[a-za-z][a-za-z0-9_]{4,15}$
10 password (beginning with letter, length between 6~18, can only contain letters, numbers, and underscores): ^[a-za-z]\w{5,17}$
11 Strong password (must contain combination of uppercase and lowercase letters and numbers, cannot use special characters, length between 8-10): ^ (? =.*\d) (? =.*[a-z]) (? =.*[a-z]). {8,10}$
12th format: ^\d{4}-\d{1,2}-\d{1,2}
131-Year 12 months (01~09 and 1~12): ^ (0?[ 1-9]|1[0-2]) $
141 months of 31 days (01~09 and 1~31): ^ (0?[ 1-9]) | ((1|2) [0-9]) |30|31) $
15 of the Money input format:
16 1. There are four forms of money that we can accept: "10000.00" and "10,000.00", and "10000" and "10,000" without "points": ^[1-9][0-9]*$
17 2. This represents any number that does not begin with 0, but it also means that a character "0" does not pass, so we take the following form: ^ (0|[ 1-9][0-9]*) $
18 3. A 0 or a number that does not begin with 0. We can also allow a minus sign at the beginning: ^ (0|-?[ 1-9][0-9]*) $
19 4. This represents a 0 or a number that may be negative at the beginning of not 0. Let the user start with 0. The minus sign is also removed, because the money can not be negative. What we're going to add here is a description of possible decimal parts: ^[0-9]+ (. [ 0-9]+)? $
20 5. It must be stated that there should be at least 1 digits after the decimal point, so "10." is not passed, but "10" and "10.2" are passed: ^[0-9]+ (. [ 0-9]{2})? $
21 6. So we have to specify that after the decimal point must have two, if you think too harsh, you can: ^[0-9]+ (. [ 0-9]{1,2})? $
22 7. This allows the user to write only one decimal place. Let's consider the comma in the number below: ^[0-9]{1,3} (, [0-9]{3}) * (. [ 0-9]{1,2})? $
23 8.1 to 3 digits, followed by any comma + 3 digits, the comma becomes optional, not necessarily: ^ ([0-9]+|[ 0-9]{1,3} (, [0-9]{3}) *) (. [ 0-9]{1,2})? $
24 Note: This is the end result, do not forget that "+" can be replaced with "*" If you think the empty string can also be accepted (strange, why?) Finally, don't forget to use the function to remove the backslash, the general error is here
XML file: ^ ([a-za-z]+-?) +[a-za-z0-9]+\\. [x| x][m| m][l| l]$
26 Regular expression of Chinese character: [\u4e00-\u9fa5]
27 Double-byte characters: [^\x00-\xff] (including Chinese characters, which can be used to compute the length of a string (a two-byte character-length meter 2,ascii character count 1))
28 Regular Expressions for blank lines: \n\s*\r (can be used to delete blank lines)
The regular expression:< for HTML tags (\s*?) [^>]*>.*?</\1>|<.*? /> (online version is too bad, this can only be part of the complex nested tags still powerless)
30 regular expressions of the first-end whitespace characters: ^\s*|\s*$ or (^\s*) | (\s*$) (can be used to delete whitespace characters (including spaces, tabs, page breaks, and so on) at the end of the line, very useful expressions)
31 Tencent QQ Number: [1-9][0-9]{4,} (Tencent QQ number starts from 10000)
32 China ZIP Code: [1-9]\d{5} (?! \d) (China postal Code is 6 digits)
IP address: \d+\.\d+\.\d+\.\d+ (useful when extracting IP addresses)

Wonderful topic sharing:jquery Plugin Validate verification method Rollup

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.