Validate phone number with JavaScript

前端 未结 26 1733

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:26

    try this

    /^[\+]?\d{2,}?[(]?\d{2,}[)]?[-\s\.]?\d{2,}?[-\s\.]?\d{2,}[-\s\.]?\d{0,9}$/im
    

    valid formats:

    1. (123) 456-7890
    2. (123)456-7890
    3. 123-456-7890
    4. 123.456.7890
    5. 1234567890
    6. +31636363634
    7. +3(123) 123-12-12
    8. +3(123)123-12-12
    9. +3(123)1231212
    10. +3(123) 12312123
    11. 075-63546725

提交回复
热议问题