Phone validation regex

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

    Try this

    \+?\(?([0-9]{3})\)?[-.]?\(?([0-9]{3})\)?[-.]?\(?([0-9]{4})\)?
    

    It matches the following cases

    • +123-(456)-(7890)
    • +123.(456).(7890)
    • +(123).(456).(7890)
    • +(123)-(456)-(7890)
    • +123(456)(7890)
    • +(123)(456)(7890)
    • 123-(456)-(7890)
    • 123.(456).(7890)
    • (123).(456).(7890)
    • (123)-(456)-(7890)
    • 123(456)(7890)
    • (123)(456)(7890)

    For further explanation on the pattern CLICKME

提交回复
热议问题