JS verification mobile phone number (up to now various number segments)

Source: Internet
Author: User

Function checkmobile (){
VaR Tel = $ ('. tel'). Val ();

VaR MSG = $ ('# msg_tel ');

/*
"/" Represents a regular expression.
"^" Indicates the start position of the string, and "$" indicates the end position of the string.
"?" It indicates matching one or zero characters before, so here 0? The mobile phone number can start with 0 or not.
Next, verify the 11-digit mobile phone number starting from 13. The range is [0-9] Because the 11-digit mobile phone number is available from 130-139. the number starting with 15 is not 154, so [] does not contain the number 4. Of course, it can also be written as [0-35-9]. The numbers listed in the 18 and 14 below are the same as those listed in the preceding figure.
Enclosed in parentheses represents a subexpression, which contains four optional branches separated by "|". In regular expressions, "|" has the lowest priority, here, each branch matches three characters (one [] can only match one character, which is optional), that is, the first three digits of the mobile phone number, then there are 8 digits to be matched, which can be any 0-9 character. Therefore, the value is "[0-9] {8}", and the number in {} indicates the number that matches the previous character. The analysis is complete.
*/

VaR regu =/^ 0? (13 [0-9] | 15 [012356789] | 18 [0236789] | 14 [57]) [0-9] {8} $ /;
VaR Re = new Regexp (regu );
If (Re. Test (TEL )){
MSG. removeclass ('msgtel ');
MSG. addclass ('msg ');
Return true;
} Else {
MSG. removeclass ('msg ');
MSG. addclass ('msgtel ');
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.