JS Verify phone number is legal

Source: Internet
Author: User

/********************
Function Name: Istelephone
function function: fixed, mobile phone number check function, return True, reverse, return false
function parameters: obj, number to be checked
Check rule:
(1) Number, "(", ")" and "-"
(2) The phone number is 3 to 8 digits
(3) If the phone number contains an area code, then the area code is three-bit or four-bit
(4) The area code is separated by "(", ")" or "-" and other parts
(5) The mobile phone number is 11 or 12 bits, if 12 bits, then the first digit is 0
(6) The first and second digits of the 11-digit mobile phone number are "13"
(7) The second and third digits of the 12-digit mobile phone number are "13"
********************/
function Istelephone (obj)//Regular judgment
{
var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$) | (^[0-9]{3,8}$) | (^\ ([0-9]{3,4}\) [0-9]{3,8}$] | (^0{0,1}13[0-9]{9}$)/;
if (pattern.test (obj))
{
return true;
}
Else
{
return false;
}
}

function Isphonenumber (str) non-regular judgment
{
var I,strlengh,tempchar;
Str=cstr (str);
if (str== "") return false;
Strlength=str.length;
for (i=0;i<strlength;i++)
{
Tempchar=str.substring (i,i+1);
if (! ( tempchar==0| | tempchar==1| | tempchar==2| | tempchar==3| | tempchar==4| | tempchar==5| | tempchar==6| | tempchar==7| | tempchar==8| |tempchar==9| | tempchar== ';-';))
{
Alert ("Phone number can only enter numbers and dashes");
return (false);
}
}
return (true);
}

JS Verify phone number is legal

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.