Javascript Regular Expression for International Phone Number

前端 未结 4 1506
有刺的猬
有刺的猬 2021-02-06 17:05

The following regular expression isn\'t working for international phone numbers that can allow up to 15 digits:

^[a-zA-Z0-9-().\\s]{10,15}$

W

4条回答
  •  失恋的感觉
    2021-02-06 18:06

    Try adding a backslash:

    var unrealisticPhoneNumberRegex = /^[a-zA-Z0-9\-().\s]{10,15}$/;
    

    Now it's still not very useful because you allow an arbitrary number of punctuation characters too. Really, validating a phone number like this — especially if you want it to really work for all possible international phone numbers — is probably a hopeless task. I suggest you go with what @BalusC suggests.

提交回复
热议问题