Regular Expression to determine the carrier js Code modified

Source: Internet
Author: User

Function: determines the carrier of the entered number.
This function is implemented according to the following standards:
Mobile: 134-139 151 188
China Unicom: 130-132 156
Telecom: 133 189 155
No data information will be displayed for number queries outside of these number segments.
At the same time, the number carrier changes and there is uncertainty due to the implementation of carrying numbers into the network.
This program is only used for regular expression learning and communication and can be freely transmitted, but the author is not responsible for the errors caused by this program!

Copy codeThe Code is as follows: <Script language = "javascript" type = "text/javascript">
/**
Designed By Androidyue
Date: 2011-01-20
Function: determines the carrier of the entered number.
This function is implemented according to the following standards:
Mobile: 134-139 151 188
China Unicom: 130-132 156
Telecom: 133 189 155
No data information will be displayed for number queries outside of these number segments.
At the same time, the number carrier changes and there is uncertainty due to the implementation of carrying numbers into the network.
This program is only used for regular expression learning and communication and can be freely transmitted, but the author is not responsible for the errors caused by this program!
**/
Function getServiceProvider (){
// Obtain the user input box information
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 blank ");
Return;
}
// If the user does not input 11-Bit Data
If (phoneNumber. length! = 11 ){
Alert ("enter an 11-digit standard mobile phone number ");
Return;
}
// Set matching regular expression content
Var re =/1 (/d) (/d {8 })/;
// Match the string
Var arrResult = phoneNumber. match (re );
// If no matching result exists
If (arrResult = null ){
Alert ("check whether the phone number you entered exists or contains non-numeric characters ");
Return;
} Else {
// If (arrResult. length! = 0 ){
If (RegExp. $1 = 3) {// if the second digit is 3, judge the third digit
Switch (RegExp. $2) {// judge the third digit
Case '0': // 130 131 132 is the China Unicom segment
Case '1 ':
Case '2 ':
Alert ("this is a China Unicom mobile number ");
Break;
Case '3': // 133 is the China Telecom number segment
Alert ("this is a telecom phone number ");
Break;
Case '4': // 134 135 136 137 138 139 is the mobile 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 the third number
Case '1': // 151 is the mobile number segment
Alert ("this is a mobile phone number ");
Break;
Case '5': // 155 is the China Unicom segment
Alert ("this is a China Unicom mobile number ");
Break;
Case '6': // 156 is the China Telecom number segment
Alert ("this is a telecom phone number ");
Break;
Default: // other phone numbers with the first two being 15 but the third being not 1 5 6 are displayed temporarily.
Alert ("no data for the phone number you entered ");
Break;
}
Return;
}
If (RegExp. $1 = 8) {// if the second digit is 8, judge the third digit.
Switch (RegExp. $2 ){
Case '8': // 188 is the mobile number segment
Alert ("this is a mobile phone number ");
Break;
Case '9': // 189 is the China Telecom number segment
Alert ("this is a telecom phone number ");
Break;
Default: // The first two other phone numbers are 18 but the third phone number is not 8 9. No data is displayed.
Alert ("no data for the phone number you entered ");
Break;
}
Return;
}
Alert ("the phone number you entered has no data ");
Return;
} // If a matched end sign exists
} // The end of the function getServiceProvider
</Script>
<Body>
Enter the phone number of the carrier you want to query:
<Input type = "text" name = "phoneInfo" id = "phoneInfo">
<Input type = "button" value = "query" onclick = "getServiceProvider ()">
</Body>
</Html>
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.