Home > Article > Web Front-end > jQuery phone number validation example
The example of this article shares the specific code of jQuery phone number verification for your reference. The specific content is as follows
Phone number verification:
//Mobile number home location supports number segment: 134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188
//Unicom number home support number segment: 130 131 132 145 155 156 176 186
//Telecom number home location support Number segment: 133 153 177 180 181 189
//Mobile operator: 170
Mobile:
2G number segment (GSM): 134-139, 150, 151, 152, 158-159;
3G number segment (TD-SCDMA): 157, 187, 188, 147.
China Unicom:
2G number segment (GSM): 130-132, 155-156;
3G number segment (WCDMA) : 185, 186.
Telecom:
2G number segment (CDMA): 133, 153;
3G number segment (CDMA2000): 180, 189.
Regular expression :
var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
Explanation: It must be an 11-digit phone number that meets the following format
˜ ˜ 13 (0-9) or 14 (0-9) or 170 or 15 (0-3) or 15 (5 -9) or 18 (0-9) + 8 digits
Note: Regular expression for positive integers (the first bit cannot be 0, such as 025 is illegal): /^[1-9][0-9]* $/
Application examples:
<html> <script type="text/javascript" src="jquery-1.12.1.js"></script> </head> <body> <span id="lblErr" style="color:Red;"></span> <input name="PhoneNumber" type="text" id="PhoneNumber" style="width: 255px;"> <input type="submit" value="提交" onclick="submitValidate()" id="btnSave"> <script> function submitValidate(){ var strPhoneNumber = $("#PhoneNumber").val(); var isMobile; if (strPhoneNumber.length > 0) { var arrayPhoneNumber = strPhoneNumber.replace(";", ";").split(";"); if (arrayPhoneNumber.length > 5) { $("#lblErr").text("手机号最多能添加5个。"); $("#lblErr").css("display", ""); return false; } else { for (var i = 0; i < arrayPhoneNumber.length; i++) { isMobile = arrayPhoneNumber[i].match(/^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/); if (!isMobile) { $("#lblErr").text("第 " + (i + 1) + " 个手机号: " + arrayPhoneNumber[i] + " 不正确。"); $("#lblErr").css("display", ""); return false; } } } } } </script> </body> </html>
The above is the entire content of this article. I hope it will be helpful to everyone's learning, and I also hope that everyone will support the PHP Chinese website.
For more jQuery phone number verification examples related articles, please pay attention to the PHP Chinese website!