JS Regular Expression for identifying landline, PHS, and mobile phone numbers

Source: Internet
Author: User

 

<HTML>

<Head>

<Title> JS Regular Expression </title>

</Head>

<Body>

<Script language = "JavaScript">

// Match a landline or PHS, for example, in the format of 031185907468 or 02185907468

Function isphone1 (){

VaR num = Document. getelementbyid ('Ph '). value;

VaR partten =/^ 0 ([1-9]/d) | ([3-9]/d {2})/d {8} $ /;

If (partten. Test (Num )){

Alert ('yesphone number ');

} Else {

Alert ('not a phone number ');

}

}

Function isphone2 (){

VaR num = Document. getelementbyid ('mb'). value;

VaR partten =/^ 1 [3, 5]/d {9} $ /;

If (partten. Test (Num )){

Alert ('mobile phone number ');

} Else {

Alert ('not a mobile phone number ');

}

}

</SCRIPT>

Enter a landline or PHS Number: <input type = "text" name = "phone" id = "PH"> <input type = "button" value = "test" onclick = "isphone1 ();">

Enter the mobile phone number: <input type = "text" name = "phone" id = "MB"> <input type = "button" value = "test" onclick = "isphone2 ();">

</Body>

</Html>

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.