PHP Regular Expression collection

Source: Internet
Author: User

The following are some common Regular Expressions collected for your reference in your work.

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: "^ \ 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 strings consisting of digits, 26 English letters, or underscores can be entered: "^ \ w + $"

Verify the User Password: "^ [a-zA-Z] \ w {5, 17} $" correct format: it must start with a letter and have a length of 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}

Instance used:

<Html> Articles you may be interested in
  • PHP Regular Expressions (2)
  • PHP Regular Expressions (1)
  • PHP Regular Expressions (3)
  • Sort regular expressions that are frequently used
  • Special characters in a regular expression
  • Summary of common Regular Expressions
  • Regular expression syntax
  • Use JavaScript to verify the regular expression of the mobile phone number

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.