Phone validation regex

后端 未结 16 1515
孤城傲影
孤城傲影 2020-11-27 02:56

I\'m using this pattern to check the validation of a phone number

^[0-9\\-\\+]{9,15}$

It\'s works for 0771234567 and +0

相关标签:
16条回答
  • 2020-11-27 03:54
    ^+?\d{3}-?\d{2}-?\d{2}-?\d{3}$
    

    You may try this....

    How about this one....Hope this helps...

    ^(\\+?)\d{3,3}-?\d{2,2}-?\d{2,2}-?\d{3,3}$
    
    0 讨论(0)
  • 2020-11-27 03:55
    The following regex matches a '+' followed by n digits
    
    
        var mobileNumber = "+18005551212";
        var regex = new RegExp("^\\+[0-9]*$");
        var OK = regex.test(mobileNumber);
    
        if (OK) {
          console.log("is a phone number");
        } else {
          console.log("is NOT a phone number");  
        }
    
    0 讨论(0)
  • 2020-11-27 03:55
    /^(([+]{0,1}\d{2})|\d?)[\s-]?[0-9]{2}[\s-]?[0-9]{3}[\s-]?[0-9]{4}$/gm
    

    https://regexr.com/4n3c4

    Tested for

    +94 77 531 2412

    +94775312412

    077 531 2412

    0775312412

    77 531 2412

    // Not matching

    77-53-12412

    +94-77-53-12412

    077 123 12345

    77123 12345

    0 讨论(0)
  • 2020-11-27 03:57

    First test the length of the string to see if it is between 9 and 15.

    Then use this regex to validate:

    ^\+?\d+(-\d+)*$
    

    This is yet another variation of the normal* (special normal*)* pattern, with normal being \d and special being -.

    0 讨论(0)
提交回复
热议问题