Although there are not many users using asp. there are still a lot of people. Next I will introduce some common codes for mobile phone number Regular Expression verification in asp. You can refer to them.
(China Mobile phone no. 134,135,136,137,138,139,150,151,157,158,159, China Unicom's no. 130,131,132,133,153,155,156, China Telecom's 3G mobile phone no. 188, and China Netcom's 3G mobile phone no. 189)
1. The first three digits must be 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 150, 151, 153, 156, 157, 158, one of the 159, 188, and 189, otherwise, the system prompts "invalid mobile phone number ";
2. It must be an 11-digit number;
China Mobile Phone Number: (86) * 0 * 13d {9}
China landline number: (d {3, 4}) | d {3, 4}-| s )? D {8}
Chinese phone number (including mobile phone and landline phone) :( (d {3, 4}) | d {3, 4}-| s )? D {7, 14}
The Code is as follows: |
Copy code |
Function SUBmobile (tel) Set RegEx = New RegExp RegEx. IgnoreCase = True RegEx. pattern = "^ (13 [0-9] | 15 [0 | 1 | 2 | 3 | 6 | 7 | 8 | 9] | 18 [6 | 7 | 8 | 9 ]) d {8} $" SUBmobile = RegEx. test (tel) End Function |
Call method:
The Code is as follows: |
Copy code |
MMobile = trim (request. form ("Mobile") '// obtain the Mobile phone number code. If SUBmobile (mMobile) then '// Perform the operation. The mobile phone number format is correct! Else '// Perform the operation. The mobile phone number format is incorrect! End if |
Asp verification improves the Regular Expression of mobile phone numbers in the content
The Code is as follows: |
Copy code |
Function RegExpTest (patrn, strng) Dim regEx, Match, Matches 'to create a variable. Set regEx = New RegExp 'to create a regular expression. RegEx. Pattern = patrn 'setting mode. RegEx. IgnoreCase = true' specifies whether the characters are case sensitive. RegEx. Global = true' to set Global availability. Set Matches = regEx. Execute (strng) 'to Execute the search. For Each Match in Matches 'traverses the matching set. 'Retstr = RetStr & "Match found at position" 'Retstr = RetStr & Match. FirstIndex & ". Match Value is '" RetStr = RetStr & Match. Value Next RegExpTest = RetStr End Function |
The following is an example of asp.net mobile phone number verification.
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! "); } } } } } |