jquery to validate phone number

后端 未结 9 1855
情话喂你
情话喂你 2020-12-01 06:34

I want to validate phone numbers like (123) 456-7890 or 1234567890 How should be the \'matches\' condition be written in the following code?

form.validate({         


        
9条回答
  •  被撕碎了的回忆
    2020-12-01 07:10

    Your regex should be something like

    [0-9\-\(\)\s]+.

    It matches numbers, dashes, parentheses and space.

    If you need something more strict, matching just your example, try this:

    ([0-9]{10})|(\([0-9]{3}\)\s+[0-9]{3}\-[0-9]{4})

提交回复
热议问题