JS Regular expression verifies whether it is a 11-bit valid mobile number,

Source: Internet
Author: User

74007124

Recently in the registration landing page, are involved in verifying 11 valid mobile phone numbers, posted here code, hoping to help the development needs of friends.

[JavaScript]View PlainCopy
  1. function Isponeavailable ($poneInput) {
  2. var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
  3. if (!myreg.test ($poneInput. Val ())) {
  4. return false;
  5. } Else {
  6. return true;
  7. }
  8. }


Here I directly encapsulated in a method, need to use the time to pass in a JQ object of input. Of course, you can also pass in strings directly, such as:

[JavaScript]View PlainCopy
  1. function Isponeavailable (str) {
  2. var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
  3. if (!myreg.test (str)) {
  4. return false;
  5. } Else {
  6. return true;
  7. }
  8. }

The emphasis here is on this regular expression:

[JavaScript]View PlainCopy
    1. var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;

The meaning of this expression is:

The beginning of the 1;

2--the second place may be 3,4,5,7,8, any one in;

3--ends with 9 integers of 0-9.

Originally only allow 13,15,17,18, the beginning of the mobile phone number, but the test mm said there are 14 beginning of the number, so added 14; Of course, if later developed into a 16, or 19, such as the opening number,

[JavaScript]View PlainCopy
    1. [3,4,5,7,8]

can be added.

Pro-Test feasible 20180428

2017-9-8

[JavaScript]View PlainCopy
    1. Determine if the phone number is
    2. Isponeavailable: function (pone) {
    3. var myreg =/^[1][3,4,5,7,8][0-9]{9}$/;
    4. if (!myreg.test (pone)) {
    5. return false;
    6. } Else {
    7. return true;
    8. }
    9. },
    10. //Determine if it is a phone number
    11. Istelavailable: Function (tel) {
    12. var myreg =/^ (([0\+]\d{2,3}-)? (  0\d{2,3})-) (\d{7,8}) (-(\d{3,}))? $/;
    13. if (!myreg.test (tel)) {
    14. return false;
    15. } Else {
    16. return true;
    17. }
    18. },

JS Regular expression verifies whether it is a 11-bit valid mobile number,

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.