Regular expression to determine the number of the operator JS Code modified version _ Regular expression

Source: Internet
Author: User
Function: Determine the number of operators to fill in
This function is implemented according to the following criteria
Mobile: 134-139 151 188
Unicom: 130-132 156
Telecom: 133 189 155
Queries about numbers outside these numbers will prompt no data information
At the same time, due to the implementation of the number of carrier network changes and uncertainty
This procedure only for regular expression learning exchange use, can spread at will, but the error caused by the program, the author is not responsible!

Copy Code code as follows:

<script language= "javascript" type= "Text/javascript" >
/**
Designed by Androidyue
Date:2011-01-20
Function: Determine the number of operators to fill in
This function is implemented according to the following criteria
Mobile: 134-139 151 188
Unicom: 130-132 156
Telecom: 133 189 155
Queries about numbers outside these numbers will prompt no data information
At the same time, due to the implementation of the number of carrier network changes and uncertainty
This procedure only for regular expression learning exchange use, can spread at will, but the error caused by the program, the author is not responsible!
**/
function GetServiceProvider () {
Get information about the user input box
var Phonenumber=document.getelementbyid ("Phoneinfo"). Value;
If the user input box does not contain any information
if (phonenumber== "") {
Alert ("Enter mobile phone number information cannot be empty");
return;
}
If the user does not enter 11-bit data
if (phonenumber.length!=11) {
Alert ("Please enter a 11-digit standard mobile phone number");
return;
}
Set matching Regular expression content
var re=/1 (d) (/D) (/d{8})/;
to match a string
var arrresult=phonenumber.match (re);
If the match has no results
if (arrresult==null) {
Alert ("Please verify that the phone number you entered exists or is not included in a non-numeric character");
Return
}else{
if (arrresult.length!=0) {
if (regexp.$1==3) {//If the second digit is 3, determine the third digit
Switch (regexp.$2) {//Judge third digit
Case ' 0 '://130 131 132 is the Unicom section
Case ' 1 ':
Case ' 2 ':
Alert ("This is a Unicom mobile phone number");
Break
Case ' 3 '://133 for electrical signal segment
Alert ("This is a telecommunication cell phone number");
Break
Case ' 4 '://134 135 136 137 138 139 is a moving number segment
Case ' 5 ':
Case ' 6 ':
Case ' 7 ':
Case ' 8 ':
Case ' 9 ':
Alert ("This is a mobile phone number");
Break
}
Return
}
if (regexp.$1==5) {//If the second digit is 5
Switch (regexp.$2) {//Judge a third number
Case ' 1 '://151 is a moving number segment
Alert ("This is a mobile phone number");
Break
Case ' 5 '://155 is the Unicom section
Alert ("This is a Unicom mobile phone number");
Break
Case ' 6 '://156 is an electrical signal segment
Alert ("This is a telecommunication cell phone number");
Break
default://the other top 2 is 15 but the third is not 1 5 6 phone number, temporarily show no data
Alert ("You enter the mobile phone number no data");
Break
}
Return
}
if (regexp.$1==8) {//If the second digit is 8 to judge the third digit
Switch (regexp.$2) {
Case ' 8 '://188 is a moving number segment
Alert ("This is a mobile phone number");
Break
Case ' 9 '://189 is an electrical signal segment
Alert ("This is a telecommunication cell phone number");
Break
default://the other top two digits are 18 but the third is not 8 9 phone number, showing no data
Alert ("You enter the mobile phone number no data");
Break
}
Return
}
Alert ("The number you entered has no data");
Return
}//If there is a matching end flag
}//the end of the function GetServiceProvider
</script>
<body>
Please enter the phone number of the operator you want to inquire:
<input type= "text" name= "Phoneinfo" id= "Phoneinfo" >
<input type= "button" value= "Query" onclick= "GetServiceProvider ()" >
</body>

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.