JS Phone number verification function

Source: Internet
Author: User

Requirements: One, mobile phone number is 11 or 12 digits, if 12 digits, then the first digit is 0
The first and second digits of the 11-digit mobile phone number are "13"
The second and third digits of the 12-digit mobile phone number are "13"
Purpose: Check whether the input mobile phone number is correct
Input:
S: string
Return:
Returns False if the validation returns true
*/
Java code

1. function F_check_mobile (obj) {
2. var regu =/(^[1][3][0-9]{9}$) | (^0[1][3][0-9]{9}$)/;
3. var re = new RegExp (Regu);
4. if (Re.test (Obj.value)) {
5. return true;
6.}
7. F_alert (obj, "Please enter the correct mobile phone number");
8. return false;
9.}
10.

function F_check_mobile (obj) {
var regu =/(^[1][3][0-9]{9}$) | (^0[1][3][0-9]{9}$)/;
var re = new RegExp (Regu);
if (Re.test (Obj.value)) {
return true;
}
F_alert (obj, "Please enter the correct mobile phone number");
return false;
}


/*
Requirements: First, the number of telephone numbers, "(", ")" and "-" constitute
Two, the telephone number is 3 to 8 digits
If the phone number contains an area code, then the area code is three digits or four digits
Four, the area code with "(", ")" or "-" and other parts separated
Purpose: Check the format of the phone number you entered correctly
Input:
Strphone: String
Return:
Returns False if the validation returns true
*/
Java code

  1. function F_check_phone (obj)   
   2. { 
   3.     var regu =/(^ ([0][1-9]{2,3}[-]) d{3,8} (-d{1,6})? $) | ( ^ ([0][1-9]{2,3}) d{3,8} ((d{1,6})? $) | (^d{3,8}$)/;  
   4.     var re = new RegExp (regu); 
   5.     if (re.test (obj.value)) { 
   6.       return true; 
   7.    } 
   8.     f_ Alert (obj, "Please enter the correct phone number"); 
   9.     return false; 
  10.}  
  11.   

Function F_check_phone (obj)
{
    var regu =/(^ ([0][1-9]{2,3}[-]) d{3,8} (-d{1,6})? $) | ( ^ ([0][1-9]{2,3}) d{3,8} ((d{1,6})? $) | (^d{3,8}$)/;
    var re = new RegExp (Regu);
    if (re.test (Obj.value)) {
      return true;
  & nbsp
    F_alert (obj, "Please enter the correct phone number");
    return false;
}

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.