国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 The most comprehensive commonly used regular expressions

The most comprehensive commonly used regular expressions

Nov 10, 2016 am 10:06 AM

1. Expression of check digits

1 Number: ^[0-9]*$

2 n-digit number: ^d{n}$

3 At least n-digit number: ^d{n, }$

4 m-n digit numbers: ^d{m,n}$

5 Numbers starting with zero and non-zero: ^(0|[1-9][0-9]*)$

6 Non Numbers starting with zero with up to two decimal places: ^([1-9][0-9]*)+(.[0-9]{1,2})?$

7 with 1-2 decimal places Positive or negative numbers: ^(-)?d+(.d{1,2})?$

8 Positive numbers, negative numbers, and decimals: ^(-|+)?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 Non-zero positive integer: ^[1-9]d*$ or ^([1-9][0-9]*){1, 3}$ or ^+?[1-9][0-9]*$

12 Non-zero negative integer: ^-[1-9][]0-9"*$ or ^-[1-9 ]d*$

13 Non-negative integer: ^d+$ or ^[1-9]d*|0$

14 Non-positive integer: ^-[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 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]*))$

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 number: ^(-?d+)(.d+)?$ or ^-?([1-9]d*.d*|0.d*[1-9]d*|0? .0+|0)$


2. Expression of check characters

1 Chinese characters: ^[u4e00-u9fa5]{0,}$

2 English and numbers: ^[A-Za-z0 -9]+$ or ^[A-Za-z0-9]{4,40}$

3 All characters with length 3-20: ^.{3,20}$

4 consisting of 26 English letters String consisting of: ^[A-Za-z]+$

5 String consisting of 26 uppercase English 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, numbers including underscores: ^[u4E00-u9FA5A-Za-z0-9_]+$

10 Chinese, English, numbers but not including underscores and other symbols :^[u4E00-u9FA5A-Za-z0-9]+$ or ^[u4E00-u9FA5A-Za-z0-9]{2,20}$

11 can be entered containing ^%&',;=?$" Characters such as: [^%&',;=?$x22]+

12 It is forbidden to enter characters containing ~: [^~x22]+


3. Expressions for special needs

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 phone number ("XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX-XXXXXX", "XXX-XXXXXXXX", "XXXXXXX "and"XXXXXXXX): ^((d{3,4}-)|d{3.4}-)?d{7,8}$

6 Domestic phone number (0511-4405222, 021-87888822): d{ 3}-d{8}|d{4}-d{7}

7 ID number (15 digits, 18 digits): ^d{15}|d{18}$

8 Short ID number (Ending with numbers and letters x): ^([0-9]){7,18}(x|X)?$ or ^d{8,18}|[0-9x]{8,18}|[0 -9X]{8,18}?$

9 Is the account legal (starting with a letter, 5-16 bytes allowed, alphanumeric underscores allowed): ^[a-zA-Z][a-zA-Z0-9_] {4,15}$

10 Password (starting with a letter, length between 6~18, can only contain letters, numbers and underscores): ^[a-zA-Z]w{5,17}$

11 Strong password (must contain a combination of uppercase and lowercase letters and numbers, cannot use special characters, length is between 8-10): ^(?=.*d)(?=.*[a-z])(?=.* [A-Z]).{8,10}$

12 Date format: ^d{4}-d{1,2}-d{1,2}

13 12 months of the year (01~09 and 1~12): ^(0?[1-9]|1[0-2])$

14 31 days of a month (01~09 and 1~31): ^((0?[1-9 ])|((1|2)[0-9])|30|31)$

15 Input format of money:

16 1. There are four representations of money that we can accept: "10000.00" and " 10,000.00", and "10000" and "10,000" without "cent": ^[1-9][0-9]*$

17 2. This means any number that does not start with 0, but this also It means that a character "0" is not passed, so we use the following form: ^(0|[1-9][0-9]*)$

18 3. A 0 or a number that does not start with 0. We can also allow a negative sign at the beginning: ^(0|-?[1-9][0-9]*)$

19 4. This means a 0 or a number that does not start with 0 that may be negative Let the user start with 0. Also remove the negative sign, because money cannot be negative. What we need to add next is to indicate the possible decimal part: ^[0-9]+(.[0-9 ]+)?$

20 5. It must be noted that there should be at least 1 digit after the decimal point, so "10." is not passed, but "10" and "10.2" are passed: ^[0- 9]+(.[0-9]{2})?$

21 6. In this way, we stipulate that there must be two digits after the decimal point. If you think it is too harsh, you can do this: ^[0-9]+(. [0-9]{1,2})?$

22 7. This allows the user to write only one decimal place. Next we should consider the comma in the number, we can do this: ^[0-9]{1 ,3}(,[0-9]{3})*(.[0-9]{1,2})?$

23 8.1 to 3 numbers, followed by any number of commas + 3 numbers, commas become optional instead of required: ^([0-9]+|[0-9]{1,3}(,[0 -9]{3})*)(.[0-9]{1,2})?$

24 Note: This is the final result, don't forget that "+" can be replaced with "*" if you feel If the empty string is also acceptable (strange, why?) Finally, don’t forget to remove the backslash when using the function. Common errors are here

25 xml file: ^([a-zA-Z] +-?)+[a-zA-Z0-9]+\.[x|X][m|M][l|L]$

26 Regular expression for Chinese characters: [u4e00-u9fa5]

27 Double-byte characters: [^x00-xff] (including Chinese characters, can be used to calculate the length of a string (the length of a double-byte character counts as 2, and the length of an ASCII character counts as 1)) 28 Regular expression for blank lines: ns*r (can be used to delete blank lines)

29 Regular expression for HTML tags: ]*>.*?1>|<.> (The version circulating on the Internet is too bad. The above one is only partially effective and is still powerless for complex nested tags.) 30 Regular expression for leading and trailing whitespace characters: ^s*|s*$ or (^s*)|(s*$) (It can be used to delete blank characters at the beginning and end of the line (including spaces, tabs, form feeds, etc.), a very useful expression)

31 Tencent QQ number: [1-9][0-9] {4,} (Tencent QQ number starts from 10000)

32 China postal code: [1-9]d{5}(?!d) (China postal code is 6 digits)

33 IP address: d+. d+.d+.d+ (useful when extracting IP address) 34 IP address: ((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\ .){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))

"^d+$" //Non-negative integer ( Positive integer + 0)
"^[0-9]*[1-9][0-9]*$" //Positive integer
"^((-d+)|(0+))$" //Not Positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$" //Negative integer
"^-?d+$" //Integer
"^d+ (.d+)?$" //Non-negative floating point number (positive floating point number + 0)
"^(([0-9]+.[0-9]*[1-9][0-9]*) |([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$" //Positive floating point number
"^((-d+(.d+)?)|(0+(.0+)?))$" //Non-positive floating point number (negative floating point number + 0)
"^(- (([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0- 9]+)|([0-9]*[1-9][0-9]*)))$" //Negative floating point number
"^(-?d+)(.d+)?$" // Floating point number
"^[A-Za-z]+$" //A string consisting of 26 English letters
"^[A-Z]+$" //A string consisting of 26 uppercase English letters
" ^[a-z]+$" //A string consisting of 26 lowercase English letters
"^[A-Za-z0-9]+$" //A string consisting of numbers and 26 English letters
" ^w+$" //A string consisting of numbers, 26 English letters or underscores
"^[w-]+(.[w-]+)*@[w-]+(.[w-]+) +$" //email address
"^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$" / /url

Integer or decimal: ^[0-9]+.{0,1}[0-9]{0,2}$
Only numbers can be entered: "^[0-9]*$".
Only n-digit numbers can be entered: "^d{n}$".
You can only enter a number with at least n digits: "^d{n,}$".
Only m~n digits can be entered:. "^d{m,n}$"
You can only enter numbers starting with zero and non-zero: "^(0|[1-9][0-9]*)$".
Only positive real numbers with two decimal places can be entered: "^[0-9]+(.[0-9]{2})?$".
You can only enter positive real numbers with 1~3 decimal places: "^[0-9]+(.[0-9]{1,3})?$".
Only non-zero positive integers can be entered: "^+?[1-9][0-9]*$".
Only non-zero negative integers can be entered: "^-[1-9][]0-9"*$.
Only characters with a length of 3 can be entered: "^.{3}$".
You can only enter a string consisting of 26 English letters: "^[A-Za-z]+$".
You can only enter a string consisting of 26 uppercase English letters: "^[A-Z]+$".
You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of numbers and 26 English letters: "^[A-Za-z0-9]+$".
You can only enter a string consisting of numbers, 26 English letters or underscores: "^w+$".
Verify user password: "^[a-zA-Z]w{5,17}$" The correct format is: starting with a letter, the length is between 6 and 18, and can only contain characters, numbers and underscores.
Verify whether it contains characters such as ^%&'',;=?$": "[^%&'',;=?$x22]+".
Only Chinese characters can be entered: "^[u4e00-u9fa5]{0 ,}$"
Verify email address: "^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$".
Verify InternetURL: "^ http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$".
Verification phone number: "^((d{3,4}-)|d{3.4}-)?d{7,8}$" The correct format is: "XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX -XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX".
Verify ID number (15 or 18 digits): "^d{15}|d{18}$".
Verify the 12 months of a year: "^(0?[1-9]|1[0-2])$" The correct format is: "01"~"09" and "1"~"12".
Verify the 31 days of a month: "^((0?[1-9])|((1|2)[0-9])|30|31)$" The correct format is; "01"~"09 "and"1"~"31". Integer or decimal: ^[0-9]+.{0,1}[0-9]{0,2}$
Only numbers can be entered: "^[0-9]*$".
Only n-digit numbers can be entered: "^d{n}$".
You can only enter a number with at least n digits: "^d{n,}$".
Only m~n digits can be entered:. "^d{m,n}$"
You can only enter numbers starting with zero and non-zero: "^(0|[1-9][0-9]*)$".
Only positive real numbers with two decimal places can be entered: "^[0-9]+(.[0-9]{2})?$".
You can only enter positive real numbers with 1~3 decimal places: "^[0-9]+(.[0-9]{1,3})?$".
Only non-zero positive integers can be entered: "^+?[1-9][0-9]*$".
Only non-zero negative integers can be entered: "^-[1-9][]0-9"*$.
Only characters with a length of 3 can be entered: "^.{3}$".
You can only enter a string consisting of 26 English letters: "^[A-Za-z]+$".
You can only enter a string consisting of 26 uppercase English letters: "^[A-Z]+$".
You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of numbers and 26 English letters: "^[A-Za-z0-9]+$".
You can only enter a string consisting of numbers, 26 English letters or underscores: "^w+$".
Verify user password: "^[a-zA-Z]w{5,17}$" The correct format is: starting with a letter, the length is between 6 and 18, and can only contain characters, numbers and underscores.
Verify whether it contains characters such as ^%&'',;=?$": "[^%&'',;=?$x22]+".
Only Chinese characters can be entered: "^[u4e00-u9fa5]{0 ,}$"
Verify email address: "^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$".
Verify InternetURL: "^ http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$".
Verification phone number: "^((d{3,4}-)|d{3.4}-)?d{7,8}$" The correct format is: "XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX -XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX".
Verify ID number (15 or 18 digits): "^d{15}|d{18}$".
Verify the 12 months of a year: "^(0?[1-9]|1[0-2])$" The correct format is: "01"~"09" and "1"~"12".
Verify the 31 days of a month: "^((0?[1-9])|((1|2)[0-9])|30|31)$" The correct format is; "01"~"09 "and"1"~"31".
"^d+$" //Non-negative integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$" //Positive integer
"^((-d+ )|(0+))$" //Non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$" //Negative integer
"^ -?d+$" //Integer
"^d+(.d+)?$" //Non-negative floating point number (positive floating point number + 0)
"^(([0-9]+.[0-9]* [1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1- 9][0-9]*))$" //Positive floating point number
"^((-d+(.d+)?)|(0+(.0+)?))$" //Non-positive floating point number (Negative floating point number + 0)
"^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1- 9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //Negative floating point number
"^(- ?d+)(.d+)?$" //Floating point number
"^[A-Za-z]+$" //A string composed of 26 English letters
"^[A-Z]+$" //Consisted of A string of 26 uppercase English letters
"^[a-z]+$" //A string of 26 lowercase English letters
"^[A-Za-z0-9]+$" //A string consisting of numbers and 26 English letters
"^w+$" //A string consisting of numbers, 26 English letters or underscores
" ^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$" //email address
"^[a-zA-z]+:// (w+(-w+)*)(.(w+(-w+)*))*(?S*)?$" //url

Integer or decimal: ^[0-9]+.{0,1}[0-9]{0,2}$
Only numbers can be entered: "^[0-9]*$".
Only n-digit numbers can be entered: "^d{n}$".
You can only enter a number with at least n digits: "^d{n,}$".
Only m~n digits can be entered:. "^d{m,n}$"
You can only enter numbers starting with zero and non-zero: "^(0|[1-9][0-9]*)$".
Only positive real numbers with two decimal places can be entered: "^[0-9]+(.[0-9]{2})?$".
You can only enter positive real numbers with 1~3 decimal places: "^[0-9]+(.[0-9]{1,3})?$".
Only non-zero positive integers can be entered: "^+?[1-9][0-9]*$".
Only non-zero negative integers can be entered: "^-[1-9][]0-9"*$.
Only characters with a length of 3 can be entered: "^.{3}$".
You can only enter a string consisting of 26 English letters: "^[A-Za-z]+$".
You can only enter a string consisting of 26 uppercase English letters: "^[A-Z]+$".
You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of numbers and 26 English letters: "^[A-Za-z0-9]+$".
You can only enter a string consisting of numbers, 26 English letters or underscores: "^w+$".
Verify user password: "^[a-zA-Z]w{5,17}$" The correct format is: starting with a letter, the length is between 6 and 18, and can only contain characters, numbers and underscores.
Verify whether it contains characters such as ^%&'',;=?$": "[^%&'',;=?$x22]+".
Only Chinese characters can be entered: "^[u4e00-u9fa5]{0 ,}$"
Verify email address: "^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$".
Verify InternetURL: "^ http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$".
Verification phone number: "^((d{3,4}-)|d{3.4}-)?d{7,8}$" The correct format is: "XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX -XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX".
Verify ID number (15 or 18 digits): "^d{15}|d{18}$".
Verify the 12 months of a year: "^(0?[1-9]|1[0-2])$" The correct format is: "01"~"09" and "1"~"12".
Verify the 31 days of a month: "^((0?[1-9])|((1|2)[0-9])|30|31)$" The correct format is; "01"~"09 "and"1"~"31". Integer or decimal: ^[0-9]+.{0,1}[0-9]{0,2}$
Only numbers can be entered: "^[0-9]*$".
Only n-digit numbers can be entered: "^d{n}$".
You can only enter a number with at least n digits: "^d{n,}$".
Only m~n digits can be entered:. "^d{m,n}$"
You can only enter numbers starting with zero and non-zero: "^(0|[1-9][0-9]*)$".
Only positive real numbers with two decimal places can be entered: "^[0-9]+(.[0-9]{2})?$".
You can only enter positive real numbers with 1~3 decimal places: "^[0-9]+(.[0-9]{1,3})?$".
Only non-zero positive integers can be entered: "^+?[1-9][0-9]*$".
Only non-zero negative integers can be entered: "^-[1-9][]0-9"*$.
Only characters with a length of 3 can be entered: "^.{3}$".
You can only enter a string consisting of 26 English letters: "^[A-Za-z]+$".
You can only enter a string consisting of 26 uppercase English letters: "^[A-Z]+$".
You can only enter a string consisting of 26 lowercase English letters: "^[a-z]+$".
You can only enter a string consisting of numbers and 26 English letters: "^[A-Za-z0-9]+$".
You can only enter a string consisting of numbers, 26 English letters or underscores: "^w+$".
Verify user password: "^[a-zA-Z]w{5,17}$" The correct format is: starting with a letter, the length is between 6 and 18, and can only contain characters, numbers and underscores.
Verify whether it contains characters such as ^%&'',;=?$": "[^%&'',;=?$x22]+".
Only Chinese characters can be entered: "^[u4e00-u9fa5]{0 ,}$"
Verify email address: "^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$".
Verify InternetURL: "^ http://([w-]+.)+[w-]+(/[w-./?%&=]*)?$".
Verification phone number: "^((d{3,4}-)|d{3.4}-)?d{7,8}$" The correct format is: "XXX-XXXXXXX", "XXXX-XXXXXXXX", "XXX -XXXXXXX", "XXX-XXXXXXXX", "XXXXXXX" and "XXXXXXXX".
Verify ID number (15 or 18 digits): "^d{15}|d{18}$".
Verify the 12 months of a year: "^(0?[1-9]|1[0-2])$" The correct format is: "01"~"09" and "1"~"12".
Verify the 31 days of a month: "^((0?[1-9])|((1|2)[0-9])|30|31)$" The correct format is; "01"~"09 "and"1"~"31".
"^d+$" //Non-negative integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$" //Positive integer
"^((-d+ )|(0+))$" //Non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$" //Negative integer
"^ -?d+$" //Integer
"^d+(.d+)?$" //Non-negative floating point number (positive floating point number + 0)
"^(([0-9]+.[0-9]* [1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1- 9][0-9]*))$" //Positive floating point number
"^((-d+(.d+)?)|(0+(.0+)?))$" //Non-positive floating point number (Negative floating point number + 0)
"^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1- 9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //Negative floating point number
"^(- ?d+)(.d+)?$" //Floating point number
"^[A-Za-z]+$" //A string composed of 26 English letters
"^[A-Z]+$" //Consisted of A string of 26 uppercase English letters
"^[a-z]+$" //A string of 26 lowercase English letters
"^[A-Za-z0-9]+$" //A string consisting of numbers and 26 English letters
"^w+$" //A string consisting of numbers, 26 English letters or underscores
" ^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$" //email address
"^[a-zA-z]+:// (w+(-w+)*)(.(w+(-w+)*))*(?S*)?$" //url

整數(shù)或者小數(shù):^[0-9]+\.{0,1}[0-9]{0,2}$?
只能輸入數(shù)字:"^[0-9]*$"。?
只能輸入n位的數(shù)字:"^\d{n}$"。?
只能輸入至少n位的數(shù)字:"^\d{n,}$"。?
只能輸入m~n位的數(shù)字:。"^\d{m,n}$"?
只能輸入零和非零開(kāi)頭的數(shù)字:"^(0|[1-9][0-9]*)$"。?
只能輸入有兩位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{2})?$"。?
只能輸入有1~3位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{1,3})?$"。?
只能輸入非零的正整數(shù):"^\+?[1-9][0-9]*$"。?
只能輸入非零的負(fù)整數(shù):"^\-[1-9][]0-9"*$。?
只能輸入長(zhǎng)度為3的字符:"^.{3}$"。?
只能輸入由26個(gè)英文字母組成的字符串:"^[A-Za-z]+$"。?
只能輸入由26個(gè)大寫(xiě)英文字母組成的字符串:"^[A-Z]+$"。?
只能輸入由26個(gè)小寫(xiě)英文字母組成的字符串:"^[a-z]+$"。?
只能輸入由數(shù)字和26個(gè)英文字母組成的字符串:"^[A-Za-z0-9]+$"。?
只能輸入由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串:"^\w+$"。?
驗(yàn)證用戶(hù)密碼:"^[a-zA-Z]\w{5,17}$"正確格式為:以字母開(kāi)頭,長(zhǎng)度在6~18之間,只能包含字符、數(shù)字和下劃線。?
驗(yàn)證是否含有^%&'',;=?$\"等字符:"[^%&'',;=?$\x22]+"。?
只能輸入漢字:"^[\u4e00-\u9fa5]{0,}$"?
驗(yàn)證Email地址:"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"。?
驗(yàn)證InternetURL:"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$"。?
驗(yàn)證電話號(hào)碼:"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$"正確格式為:"XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX"。?
驗(yàn)證身份證號(hào)(15位或18位數(shù)字):"^\d{15}|\d{18}$"。?
驗(yàn)證一年的12個(gè)月:"^(0?[1-9]|1[0-2])$"正確格式為:"01"~"09"和"1"~"12"。?
驗(yàn)證一個(gè)月的31天:"^((0?[1-9])|((1|2)[0-9])|30|31)$"正確格式為;"01"~"09"和"1"~"31"。整數(shù)或者小數(shù):^[0-9]+\.{0,1}[0-9]{0,2}$?
只能輸入數(shù)字:"^[0-9]*$"。?
只能輸入n位的數(shù)字:"^\d{n}$"。?
只能輸入至少n位的數(shù)字:"^\d{n,}$"。?
只能輸入m~n位的數(shù)字:。"^\d{m,n}$"?
只能輸入零和非零開(kāi)頭的數(shù)字:"^(0|[1-9][0-9]*)$"。?
只能輸入有兩位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{2})?$"。?
只能輸入有1~3位小數(shù)的正實(shí)數(shù):"^[0-9]+(.[0-9]{1,3})?$"。?
只能輸入非零的正整數(shù):"^\+?[1-9][0-9]*$"。?
只能輸入非零的負(fù)整數(shù):"^\-[1-9][]0-9"*$。?
只能輸入長(zhǎng)度為3的字符:"^.{3}$"。?
只能輸入由26個(gè)英文字母組成的字符串:"^[A-Za-z]+$"。?
只能輸入由26個(gè)大寫(xiě)英文字母組成的字符串:"^[A-Z]+$"。?
只能輸入由26個(gè)小寫(xiě)英文字母組成的字符串:"^[a-z]+$"。?
只能輸入由數(shù)字和26個(gè)英文字母組成的字符串:"^[A-Za-z0-9]+$"。?
只能輸入由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串:"^\w+$"。?
驗(yàn)證用戶(hù)密碼:"^[a-zA-Z]\w{5,17}$"正確格式為:以字母開(kāi)頭,長(zhǎng)度在6~18之間,只能包含字符、數(shù)字和下劃線。?
驗(yàn)證是否含有^%&'',;=?$\"等字符:"[^%&'',;=?$\x22]+"。?
只能輸入漢字:"^[\u4e00-\u9fa5]{0,}$"?
驗(yàn)證Email地址:"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"。?
驗(yàn)證InternetURL:"^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$"。?
驗(yàn)證電話號(hào)碼:"^(\(\d{3,4}-)|\d{3.4}-)?\d{7,8}$"正確格式為:"XXX-XXXXXXX"、"XXXX-XXXXXXXX"、"XXX-XXXXXXX"、"XXX-XXXXXXXX"、"XXXXXXX"和"XXXXXXXX"。?
驗(yàn)證身份證號(hào)(15位或18位數(shù)字):"^\d{15}|\d{18}$"。?
驗(yàn)證一年的12個(gè)月:"^(0?[1-9]|1[0-2])$"正確格式為:"01"~"09"和"1"~"12"。?
驗(yàn)證一個(gè)月的31天:"^((0?[1-9])|((1|2)[0-9])|30|31)$"正確格式為;"01"~"09"和"1"~"31"。?
可輸入形如2008、2008-9、2008-09、2008-9-9、2008-09-09.??? ^(\d{4}|(\d{4}-\d{1,2})|(\d{4}-\d{1,2}-\d{1,2}))$?
郵箱驗(yàn)證正則表達(dá)式?? \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*?
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(s, @"您的IP:(?[0-9\.]*)");
一.網(wǎng)絡(luò)驗(yàn)證應(yīng)用技巧

1. 驗(yàn)證 E-mail格式

public bool IsEmail(string str_Email)
   {
        return System.Text.RegularExpressions.Regex.IsMatch(str_Email,@"^([\w-\.]+)@((
[?9]1,3\.[?9]1,3\.[?9]1,3\.)|(([\w?]+\.)+))([a?zA?Z]2,4|[?9]1,3)(
?)$");
   }

2. 驗(yàn)證 IP 地址

      public bool IPCheck(string IP)
      {
          string num = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
          return Regex.IsMatch(IP,("^" + num + "\\." + num + "\\." + num + "\\." + num + "$"));
       }

3. 驗(yàn)證 URL

     public bool IsUrl(string str_url)
     {
        return System.Text.RegularExpressions.Regex.IsMatch(str_url, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
     }

二. 常用數(shù)字驗(yàn)證技巧

1. 驗(yàn)證電話號(hào)碼

   public bool IsTelephone(string str_telephone)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_telephone, @"^(\d{3,4}-)?\d{6,8}$");
    }

2. 輸入密碼條件(字符與數(shù)據(jù)同時(shí)出現(xiàn))

   public bool IsPassword(string str_password)
    {          
        return System.Text.RegularExpressions.Regex.IsMatch(str_password, @"[A-Za-z]+[0-9]");
    }

3. 郵政編號(hào)

   public bool IsPostalcode(string str_postalcode)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$");
    }

4. 手機(jī)號(hào)碼

    public bool IsHandset(string str_handset)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^[1]+[3,5]+\d{9}$");
    }

5. 身份證號(hào)

    public bool IsIDcard(string str_idcard)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_idcard, @"(^\d{18}$)|(^\d{15}$)");
    }

6. 兩位小數(shù)

    public bool IsDecimal(string str_decimal)
    {
            return System.Text.RegularExpressions.Regex.IsMatch(str_decimal, @"^[0-9]+(.[0-9]{2})?$");
    }

7. 一年的12個(gè)月

    public bool IsMonth(string str_Month)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_Month, @"^(0?[[1-9]|1[0-2])$");
    }

8. 一個(gè)月的31天

    public bool IsDay(string str_day)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_day, @"^((0?[1-9])|((1|2)[0-9])|30|31)$");
    }

9. 數(shù)字輸入

    public bool IsNumber(string str_number)
     {
        return System.Text.RegularExpressions.Regex.IsMatch(str_number, @"^[0-9]*$");
     }

10. 密碼長(zhǎng)度 (6-18位)

    public bool IsPasswLength(string str_Length)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_Length, @"^\d{6,18}$");
    }

11. 非零的正整數(shù)

    public bool IsIntNumber(string str_intNumber)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_intNumber, @"^\+?[1-9][0-9]*$");
    }

三. 常用字符驗(yàn)證技巧

1. 大寫(xiě)字母

    public bool IsUpChar(string str_UpChar)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_UpChar, @"^[A-Z]+$");
    }

2. 小寫(xiě)字母

    public bool IsLowChar(string str_UpChar)
    {
        return System.Text.RegularExpressions.Regex.IsMatch(str_UpChar, @"^[a-z]+$");
    }

3. 檢查字符串重復(fù)出現(xiàn)的詞

     private void btnWord_Click(object sender, EventArgs e)
     {
            System.Text.RegularExpressions.MatchCollection matches =
 System.Text.RegularExpressions.Regex.Matches(label1.Text, 
@"\b(?<word>\w+)\s+(\k<word>)\b", 
System.Text.RegularExpressions.RegexOptions.Compiled |          
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (matches.Count != 0)
            {
                foreach (System.Text.RegularExpressions.Match match in matches)
                {
                    string word = match.Groups["word"].Value;
                    MessageBox.Show(word.ToString(),"英文單詞");
                }
            }
            else { MessageBox.Show("沒(méi)有重復(fù)的單詞"); }
        }

4. 替換字符串

   private void button1_Click(object sender, EventArgs e)
   {           
        string strResult = System.Text.RegularExpressions.Regex.Replace(textBox1.Text, @"[A-Za-z]\*?", textBox2.Text);
        MessageBox.Show("替換前字符:" + "\n" + textBox1.Text + "\n" + 
"替換的字符:" + "\n" + textBox2.Text + "\n" +  "替換后的字符:" + "\n" + 
strResult,"替換");    }

5. 拆分字符串

  private void button1_Click(object sender, EventArgs e)
   {
        //實(shí)例: 甲025-8343243乙0755-2228382丙029-32983298389289328932893289丁
        foreach (string s in System.Text.RegularExpressions.Regex.Split(textBox1.Text,@"\d{3,4}-\d*"))
        {
            textBox2.Text+=s; //依次輸出 "甲乙丙丁"
        }
    }

6. 驗(yàn)證輸入字母

   public bool IsLetter(string str_Letter)
   {
        return System.Text.RegularExpressions.Regex.IsMatch(str_Letter, @"^[A-Za-z]+$");
   }

7. 驗(yàn)證輸入漢字

   public bool IsChinese(string str_chinese)
   {
        return System.Text.RegularExpressions.Regex.IsMatch(str_chinese, @"^[\u4e00-\u9fa5],{0,}$");
   }

8. 驗(yàn)證輸入字符串 (至少8個(gè)字符)

  public bool IsLength(string str_Length)
  {
        return System.Text.RegularExpressions.Regex.IsMatch(str_Length, @"^.{8,}$");
  }


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)