JavaScript phone number Regular expression validation function [original]_ regular expression

Source: Internet
Author: User
Copy Code code as follows:

function Checkmobile () {
var smobile = Document.mobileform.mobile.value
if (!) ( /^1[3|4|5|8][0-9]\d{4,8}$/.test (Smobile))) {
Alert ("Not a full 11-digit cell phone number or the correct number of the top seven");
Document.mobileform.mobile.focus ();
return false;
}
}

The following is the cloud Habitat Community editors on the above regular expression of the simple analysis, with the increase in the number of mobile phone numbers, we can expand their own functions, do not know the regular friends read this article should be a point ah.
This is mainly the code, and later we modify this paragraph can be
^1[3|4|5|8][0-9]\d{4,8}$
^1 representative to start with 1, now China's mobile phone number is not the other beginning, later not necessarily AH
[3|4|5|8] immediately after the top 1, can be 3 or 4 or 5 or 8 of a number, if the next 190 start cell phone number, you need the following [3|4|5|8| 9]
[0-9] represents any number in the middle of 0-9, which can be 0 or 9
\d{4,8} This \d, like [0-9], is a number in the middle of 0-9. {4,8} represents the highest 8 digits of the previous minimum 4-digit number. Why here is not the direct 8, because the cell phone number attribution to the query, according to the first 7 can know the specific address, the following 4-bit has no impact.
Here is the test code:
<script type= "Text/javascript" > Function Checkmobile () {var smobile = Document.mobileform.mobile.value If (! (/^1[3|5][0-9]\d{4,8}$/.test (Smobile)) {Alert ("not a complete 11-digit cell phone number or the correct number of the top seven"); Document.mobileform.mobile.focus (); return false; } </script> <form action= "http://ip.jb51.net/sj/mobile2.asp" name= mobileform "method=" POST "onsubmit=" return Checkmobile (); " > <input name= "mobile" Class=tdc size= "maxlength=" > <input name= "Action" type= "hidden" value=mobile& Gt <input class=bdtj name=b1 type=submit value= "Query" > </FORM>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Below is the code that the cloud-dwelling community has found from other websites. Everyone can see. We also recommend that you learn the regular expression, a lot of places to leave the regular expression is really not.
\d represents a number
For example: 1 or 2 or 3, single digit
If more than one can use the \d*
\d{7,8} represents 7-8 digits (for phone numbers)
For example: 12345678
{7,8} represents a 7-bit or 9-digit number, and the general phone number is compliant.
\d{3,} represents extension number
For example: 123,12345
{3,} indicates a minimum of 3 digits and can be more
0\d{2,3} represents the area code
For example: 021
[0\+]\d{2,3} represents the international area code
If using a minus sign connection, the complete should be
/^ ([0\+]\d{2,3}-)? (0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/

Test code:
<script language= "JavaScript" > Function testit () {var filter=/^ ([0\+]\d{2,3}-)? 0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/; Alert (Filter.test (txt.value)); } </SCRIPT> <input id=txt onchange= "Testit ()" >
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Regular expressions 30 minute Introductory Tutorials
Http://www.jb51.net/tools/zhengze.html
Regular expression base data
Http://www.jb51.net/article/18526.htm

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.