Summary of common php regular expressions

Source: Internet
Author: User
Tags regular expression

Which of the following are commonly used in web development. The authors will summarize some common regular expressions in their work.

 

Description Regular expression
URL) [A-zA-z] +: // [^ s] *
IP Address) (2 [0-4] d | 25 [0-5] | [01]? Dd ?).) {3} (2 [0-4] d | 25 [0-5] | [01]? Dd ?)
Email) W + ([-+.] w +) * @ w + ([-.] w +) *. w + ([-.] w + )*
QQ number [1-9] d {4 ,}
HTML tag (including content or self-closing) <(. *) (. *)>. * </1> | <(. *)/>
Password (consisting of numbers, upper-case letters, lower-case letters, and punctuation marks. Each password must have more than eight digits) (? = ^. {8 ,}$ )(? =. * D )(? =. * W + )(? =. * [A-Z]) (? =. * [A-z]) (?!. * N). * $
Date (year-month-day) (D {4} | d {2})-(0? ([1-9]) | (1 [1 | 2])-(0? [1-9]) | ([12] ([1-9]) | (3 [0 | 1])
Date (month/day/year) (0? [1-9] {1}) | (1 [1 | 2])/(0? [1-9] | ([12] [1-9]) | (3 [0 | 1])/(d {4} | d {2 })
Time (hour: minute, in 24-hour format) (1 | 0 ?) [0-9] | 2 [0-3]) :( [0-5] [0-9])
Chinese characters (characters) U4e00-u9fa5
Chinese and fullwidth punctuation marks (characters) U3000-u301eufe10-ufe19ufe30-ufe44ufe50-ufe6buff01-uffee
Chinese mainland fixed phone number (D {4}-| d {3 }-)? (D {8} | d {7 })
Mobile phone number in mainland China 1d {10}
China mainland ZIP code [1-9] d {5}
ID No. Of mainland China (15 or 18 digits) D {15} (dd [0-9xX])?
Non-negative integer (positive integer or zero) D +
Positive integer [0-9] * [1-9] [0-9] *
Negative integer -[0-9] * [1-9] [0-9] *
Integer -? D +
Decimal (-? D +) (. d + )?

Only numbers can be entered: "^ [0-9] * $"

Only n digits can be entered: "^ d {n} $"

Only a number of at least n digits can be entered: "^ d {n,} $"

Only m ~ can be input ~ N-digit number: "^ d {m, n} $"

Only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $"

Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $"

Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $"

Only a non-zero positive integer can be entered: "^ +? [1-9] [0-9] * $"

Only a non-zero negative integer can be entered: "^-[1-9] [0-9] * $"

Only 3 characters can be entered: "^. {3} $"

Only A string consisting of 26 English letters can be entered: "^ [A-Za-z] + $"

Only a string consisting of 26 uppercase letters can be entered: "^ [A-Z] + $"

You can only enter a string consisting of 26 lower-case English letters: "^ [a-z] + $"

Only strings consisting of digits and 26 English letters can be entered: "^ [A-Za-z0-9] + $"

Only a string consisting of digits, 26 English letters, or underscores can be entered: "^ w + $"

Verify user password: "^ [a-zA-Z] w {5, 17} $" correct format: starts with a letter and ranges from 6 ~ It can only contain characters, numbers, and underscores.

Check whether the character ^ (? : [U4e00-u9fa5] * w * s *) + $

Only Chinese characters can be entered: "^ [u4e00-u9fa5] {0,} $"

Verify Email address: "^ w + ([-+.] w +) * @ w + ([-.] w + )*. w + ([-.] w +) * $"

Verify InternetURL: "^ http: // ([w-] +.) + [w-] + (/[w -./? % & =] *)? $"

China phone number verification

Matching format: 0511-4405222, 021-87888822, 021-44055520-555, or (0511) 4405222

Regular Expression "(d {3, 4}) | d {3, 4 }-)? D {7,8} (-d {3 })*"

China Post Code Verification

Matching format: 215421

Regular expression "d {6 }"

Email verification

Match form such as: justali@justdn.com
 
Regular expression "w + ([-+.] w +) * @ w + ([-.] w +) *. w + ([-.] w + )*"

ID card verification

Matching format: 15-digit or 18-digit ID card

Regular expression "d {18} | d {15 }"

Common digit verification

Regular expression

"D {n}" n is the specified length

"D {n, m}" length range from n to m

Invalid character verification

Matching characters that exclude invalid characters such:

Regular expression ^ (? : [U4e00-u9fa5] * w * s *) + $

Date verification

Matching format: 20030718,030718

Range: 1900--2099

Regular expression (19) {1} | (20) {1}) d {2}) | d {2 }) [01] {1} d {1} [0-3] {1} d {1}

 

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.