Common regular expression statements in ASP. NET

Source: Internet
Author: User

The article has added a collection of regular expressions that are often used in development applications ~ Z English letters (case insensitive), 0 ~ 9 is composed of digits, dots, minus signs or Underscores. It must be a number, an email format, and a 24-hour matching time.

1. The account is composed of ~ Z English letters (case insensitive), 0 ~ 9 is composed of numbers, points, minus signs, or Underscores. The length is 3 ~ 18 characters, for example, kyzy_001

^ [A-Za-z0-9.-_] {} $

2. The input box must contain numbers.

^ [0-9] {1,} $

3. Email format

W + ([-+.] w +) * @ w + ([-.] w +) *. w + ([-.] w + )*

4. Only two decimal numbers can be entered in the text box.

^ [0-9] +. [0-9] {0, 2} $


Match the time in the 24-hour format

(? <Hour> [0-2] {1} d {1 }):(? <Min> [1-6] {1} d {1 })
Match the standard monthly/annually Crystal format
^ (0 [48]) | ([13579] [26]) | ([2468] [048]) 00) | ([0-9] [0-9] (0 [48]) | ([13579] [26]) | ([2468] [048]) -02-29) | (000 [1-9]) | (00 [1-9] [0-9]) | (0 [1-9] [0-9] [0-9]) | ([1-9] [0-9] [0-9] [0-9])-(0 [13578]) | (1 [02])-31) | (0 [1, 3-9]) | (1 [0-2])-(29 | 30 )) | (0 [1-9]) | (1 [0-2])-(0 [1-9]) | (1 [0-9]) | (2 [0-8]) $


========================================================== ========================================================== =

^ D {5} $


Five numeric numbers, such as the US postal code.

^ (D {5}) | (d {5}-d {4} $


5 numeric or 5 Numeric-dashes-4 numeric. Match the United States postal code in 5-digit format, or the United States postal code in 5-digit + 4-digit format.

^ (D {5} (-d {4 })? $


Same as the previous one, but more effective. Use? The four digits in the mode can be used as the optional part, instead of comparing two different modes (in another way ).

^ [+-]? D + (. d + )? $


Matches any real number with an optional symbol.

^ [+-]? D *.? D * $


It is the same as the previous one, but it also matches an empty string.

^ (20 | 21 | 22 | 23 | [01] d): [0-5] d $


Matches the time value in the 24-hour format.

/*.**/


Matching c-style comments /*...*/

 

Regular expression for date and time judgment
This is to judge the format of yyyy-mm-dd, basically taking into account the leap year and February.

^ (1 [6-9] | [2-9] d) d {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] d | 3 [01]) | (1 [6-9] | [2-9] d) d {2 }) -(0? [13456789] | 1 [012])-(0? [1-9] | [12] d | 30) | (1 [6-9] | [2-9] d) d {2})-0? 2-(0? [1-9] | 1d | 2 [0-8]) | (1 [6-9] | [2-9] d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $

The following is a time verification

^ (1 [6-9] | [2-9] d) d {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] d | 3 [01]) | (1 [6-9] | [2-9] d) d {2 }) -(0? [13456789] | 1 [012])-(0? [1-9] | [12] d | 30) | (1 [6-9] | [2-9] d) d {2})-0? 2-(0? [1-9] | 1d | 2 [0-8]) | (1 [6-9] | [2-9] d) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) (20 | 21 | 22 | 23 | [0-1]? D): [0-5]? D: [0-5]? D $

 

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.