C # Regular Expressions

Source: Internet
Author: User

I learned C # and spent a long time learning regular expressions during format verification. It took me some time to sort them out for your reference. What are the errors.

  

Using sysyem. Text. regularexpressions. // The namespace that must be referenced.

Case 1: Verify the phone number

RegEx. ismatch (str_telephone, @ "6 (\ D {3, 4 }-)? \ D {6, 8} $ ");

 

Case 2: Verify the password input conditions

RegEx. ismatch (str_password, @ "[A-Za-Z] + [0-9]");

 

 

Case 3: Verify the zip code

RegEx. ismatch (str_postalcode, @ "^ \ D {6} $ ");

 

 

Case 4: Verify the mobile phone number

RegEx. ismatch (str_handset, @ "^ [1] [3-5] \ D {9} $ ");

 

 

Case 5: Verify the ID card number

RegEx. ismatch (str_idcard, @ "(^ \ D {18 }$ | ^ \ D {15} $ ");

 

 

Case 6: Verify two decimal places

RegEx. ismatch (str_decimal, @ "^ [0-9] + \. [0-9] {2} $ ");

 

 

Case 7: Verify the month of the year

RegEx. ismatch (str_month, @ "^ (0? [[1-9] | 1 [0-2] $ ");

 

 

Case 8: Verify the day of the month

RegEx. ismatch (str_day, @ "^ (0? [[1-9] | (1 | 2) [0-9]) | 30 | 31) $ ");

 

 

Case 9: Verify Digital Input

RegEx. ismatch (str_number, @ "^ [0-9] * $ ");

 

 

Case 10: Verify the password length

RegEx. ismatch (str_length, @ "^ \ D {6-18} $ ");

 

 

Case 11: verifying a non-zero positive integer

RegEx. ismatch (str_intnumber, @ "^ \ +? [1-9] [0-9] * $ ");

 

 

Case 12: verifying a non-zero negative integer

RegEx. ismatch (str_intnumber, @ "^ \-? [1-9] [0-9] * $ ");

 

 

Case 13: Verify uppercase letters

RegEx. ismatch (str_upchar, @ "^\ [A-Z] + $ ");

 

 

Case 14: Verify lowercase letters

RegEx. ismatch (str_upchar, @ "^ \ [A-Z] + $ ");

 

 

Case 15: Check repeated words

 

 

 

Case 16: replace characters

 

 

 

Case 17: Split strings

String [] _ STR = RegEx. Split (txtsplit. Text, "[1-9]");

 

Case 18: Verify input characters

RegEx. ismatch (str_letter, @ "^ [A-Za-Z] + $ ");

 

 

Case 19: Verify Chinese Character Input

RegEx. ismatch (str_chinese, @ "^ [\ u4e00-\ u9fa5] {1,} $ ");

 

 

Case 20: Verify the input string

RegEx. ismatch (str_length, @ "^ [. {8, }$ ");

 

 

 

Case 2: Verify the email format

RegEx. ismatch (str_email,

@ "^ ([\ W \.] +) @ ([0-9] {1, 3 }\. [0-9] {1, 3 }\. [0-9] {1, 3}]) | (\ W + \.?) +) @ ([A-Za-Z] {2, 4} | [0-9] {1, 3 })(\. [A-Za-Z] {2, 4}) $ ");

 

 

 

Case 2: Verify the email format

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 + "$ "));

}

 

 

Case 2 3: Verify the URL format

 

RegEx. ismatch (str_url, @ "HTTP (s )? // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)? ");

 

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.