C # common Regular expression collation

Source: Internet
Author: User
Tags regular expression


Match phone number
Regex regphone = new Regex ("^[0-9]+[-]?[ 0-9]+[-]? [0-9]$ ");


Matching numbers
Regex regnumber = new Regex ("^[0-9]+$");


Match positive and negative integers
Regex regnumbersign = new Regex ("^[+-]?[ 0-9]+$ ");


Match decimal
Regex regdecimal = new Regex ("^[0-9]+[.]"? [0-9]+$ ");


Match positive and negative decimal
Regex regdecimalsign = new Regex ("^[+-]?[ 0-9]+[.]? [0-9]+$];//equivalent to ^[+-]?d+[.]? d+$


Match email address
A string of W-letters or numbers, as in [a-za-z0-9] syntax
Regex regemail = new Regex ("^[\w-]+@[\w-]+\." Com|net|org|edu|mil|tv|biz|info) $ ");


Match Chinese
Regex regchzn = new Regex ("[U4e00-u9fa5]");


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

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

You can enter at least n digits: "^d{n,}$".

You can enter only the number of m~n digits:. "^d{m,n}$"

Only numbers beginning with 0 and not 0 can be entered: ^ (0|[ 1-9][0-9]*) $ ".

You can only enter positive real numbers with two decimal digits: ^[0-9]+ (. [ 0-9]{2})? $ ".

You can only enter positive real numbers with 1~3 decimal places: ^[0-9]+ (. [ 0-9]{1,3})? $ ".

You can only enter a Non-zero positive integer: "^+?" [1-9] [0-9]*$].

You can only enter a Non-zero negative integer: "^-[1-9][]0-9" *$.

You can only enter characters with a length of 3: "^. {3}$ ".

You can only enter a string of 26 English letters: "^[a-za-z]+$".

You can only enter a string consisting of 26 uppercase 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 of numbers, 26 English letters, or underscores: "^w+$".

Verify user password: "^[a-za-z]w{5,17}$" is the correct format: start with a letter, length between 6~18, can only contain characters, numbers, and underscores.

Verify that there are ^%& ',; =?$ ' characters: "[^%&",; = $x 22]+ ".

Verify ID Number (15-bit or 18-digit): "^d{15}|d{18}$".

Verify 12 months of the year: "^" (0?[ 1-9]|1[0-2]) $ "The correct format is:" 01 "~" 09 "and" 1 "~" 12 ".

Verify one months of 31 days: "^ (0?[ 1-9]) | ((1|2) [0-9]) |30|31) $ "correct format for;" 01 "~" 09 "and" 1 "~" 31 ".

Related Article

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.