Validating Phone Numbers Using Javascript

前端 未结 9 2231
刺人心
刺人心 2021-01-06 00:41

I\'m working on a web form with several fields and a submit button. When the button is clicked, I have to verify that the required text boxes have been filled in and that th

9条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-06 01:03

    Having seem simply too many edge cases, I went for a simpler check:

    ^(([0-9\ \+\_\-\,\.\^\*\?\$\^\#\(\)])|(ext|x)){1,20}$

    The first thing one may point out is allowing repetition of "ext", but the purpose of this regex is to prevent users from accidentally entering email ids etc. instead of phone numbers, which it does.

提交回复
热议问题