This article describes how to use asp.net to describe China Telecom to match the regular expressions of mobile/Unicom/Telecom mobile phone numbers. For more information, see.
Simplest verification of phone numbers and mobile phone numbers
Verification phone number: Add d {3, 4}-d {7, 8} To validationexpression in the regularexPRessionvalidator attribute}
Mobile phone number: ^ [1] d {10}
This is not strict, as long as the 11-digit number is the phone number, or 3-4 in the middle-the back root 7-8 number is the phone number, we can analyze below
China Mobile 134.135.136.137.138.139.150.151.152.157.158.159.187.188, 147 (data card)
China Unicom 130.131.132.155.156.185.186
China Telecom 133.153.180.189
CDMA 1, 133,153
The Code is as follows: |
Copy code |
/// <Summary> /// Match the mobile phone number /// </Summary> Public const string PATTERN_CMCMOBILENUM = @ "^ 1 (3 [4-9] | 5 [012789] | 8 [78]) d {8} $ "; /// <Summary> /// Match the China Telecom mobile phone number /// </Summary> Public const string PATTERN_CTCMOBILENUM = @ "^ 18 [09] d {8} $ "; /// <Summary> /// Match the China Unicom mobile phone number /// </Summary> Public const string PATTERN_CUTMOBILENUM = @ "^ 1 (3 [0-2] | 5 [56] | 8 [56]) d {8} $ "; /// <Summary> /// Match the CDMA mobile phone number /// </Summary> Public const string PATTERN_CDMAMOBILENUM = @ "^ 1 [35] 3d {8} $ ";
|
Example
The Code is as follows: |
Copy code |
Using System; Using System. Collections. Generic; Using System. Text; Using System. Text. RegularExpressions; Using System. Windows. Forms; Namespace ConsoleApplication1 { Class Program { Static void Main (string [] args) { // String s = @ "^ (13 [0-9] | 15 [0 | 3 | 6 | 8 | 9]) d {8} $ "; String s = @ "^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) d {8} $ "; While (true) { String input = Console. ReadLine (); If (Regex. IsMatch (input, s )) { MessageBox. Show ("Exactly! "); } Else { MessageBox. Show ("No! "); } } } } } |