Phone validation regex

后端 未结 16 1518
孤城傲影
孤城傲影 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: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

提交回复
热议问题