Validate phone number with JavaScript

前端 未结 26 2149

I found this code in some website, and it works perfectly. It validates that the phone number is in one of these formats:
(123) 456-7890 or 123-

26条回答
  •  一向
    一向 (楼主)
    2020-11-22 05:29

    try this

    /^(\+{0,})(\d{0,})([(]{1}\d{1,3}[)]{0,}){0,}(\s?\d+|\+\d{2,3}\s{1}\d+|\d+){1}[\s|-]?\d+([\s|-]?\d+){1,2}(\s){0,}$/gm

    valid formats

    • (123) 456-7890
    • (123)456-7890
    • 123-456-7890
    • 1234567890
    • +31636363634
    • +3(123) 123-12-12
    • +3(123)123-12-12
    • +3(123)1231212
    • +3(123) 12312123
    • +3(123) 123 12 12
    • 075-63546725
    • +7910 120 54 54
    • 910 120 54 54
    • 8 999 999 99 99

    https://regex101.com/r/QXAhGV/1

提交回复
热议问题