ASP mobile phone number regular expression code

Source: Internet
Author: User
Tags regular expression

(China mainland Mobile 134,135,136,137,138,139,150,151,157,158,159 number section, China Unicom's 130,131,132,133,153,155,156 number segment and the Chinese telecom 3G mobile phone number paragraph 188, China netcom 3G Mobile phone number 189th code segment)
1, the first 3 digits must be 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 150, 151, 153, 156, 157, 158, 159, 188, 189, one of them, otherwise prompted "illegal mobile phone number";
2, must be a 11-digit number;

China Mobile phone Number: (*0*13d{9)
China fixed telephone Number: ((d{3,4}) |d{3,4}-|s)? D{8}
China telephone number (including mobile and fixed telephone):((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")) '//Get phone number code.
If Submobile (mmobile) Then
'//execute operation-Phone number format is correct!
Else
'//Perform operation-phone number format is not correct!
End If


ASP verification enhances the mobile phone number regular expression in the content

The code is as follows Copy Code

Function regexptest (PATRN, STRNG)
Dim regEx, Match, matches ' Set variable.
Set regEx = New RegExp ' establishes a regular expression.
Regex.pattern = Patrn ' Set mode.
Regex.ignorecase = True ' Sets whether character case is case-sensitive.
Regex.global = True ' Sets global availability.
Set matches = Regex.execute (strng) ' performs a search.
For the match in matches ' traversal matching collection.
' Retstr = retstr & Match found at position '
' Retstr = retstr & Match.firstindex & '. Match Value is ' "
Retstr = retstr & Match.value
Next
Regexptest = Retstr
End Function

Look below a section of ASP.net mobile phone number Verification 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 ("perfectly fit!") ");
}
Else
{
MessageBox.Show ("not fit!") ");
}
}
}
}
}

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.