regular expression to determine the number of the operator JS Code modified version: http://www.jb51.net/article/31563.htm
When doing a Web project, sometimes need to according to the user's input cell phone number to judge the operator is mobile, unicom, telecommunications or other, and then according to different operators to make corresponding processing, the following describes how to determine the number of JS mobile phone operator Code
Pure JS Code
var ischinamobile =/^134[0-8]\\d{7}$|^ (?: 13[5-9]|147|15[0-27-9]|178|18[2-478]) \\d{8}$/; Mobile aspect of the latest response var ischinaunion =/^ (?: 13[0-2]|145|15[56]|176|18[56]) \\d{8}$/; To Unicom micro-blog confirmed did not respond to var ischinatelcom =/^ (?: 133|153|177|18[019]) \\d{8}$/; Section 1349th Telecommunications did not give a response, as does not exist var isothertelphone =/^170 ([059]) \\d{7}$/;//other operators var utils = {checkmobile:function (telphone)
{telphone = This.trim (Telphone);
if (Telphone.length!==) {return This.setreturnjson (false, ' no correct phone number detected ');
} else{if (Ischinamobile.test (Telphone)) {return This.setreturnjson (true, ' move ', {name: ' Chinamobile '});
else if (Ischinaunion.test (Telphone)) {return This.setreturnjson (true, ' Unicom ', {name: ' Chinaunion '});
else if (Ischinatelcom.test (Telphone)) {return This.setreturnjson (true, ' telecom ', {name: ' chinatelcom '});
else if (Isothertelphone.test (Telphone)) {var num = isothertelphone.exec (telphone);
Return This.setreturnjson (True, ', {name: '}); } else{return This.setreturnJson (False, ' no correct phone number detected '); }}, Setreturnjson:function (Status, MSG, data) {if (TypeOf status!== ' Boolean ' && typeof status!== ' Numb
Er ') {status = FALSE;
} if (typeof msg!== ' string ') {msg = ';
return {' Status ': Status, ' msg ': MSG, ' Data ': data}; }
}
How, the above code is very simple, I hope you learn JS to determine the operation of mobile phone number is still helpful.