jquery验证电话号码 [英] jquery to validate phone number

查看:112
本文介绍了jquery验证电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证电话号码,如(123)456-7890或1234567890
如何在以下代码中写入'匹配'条件?

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({

    rules: {

       phoneNumber: {matches:"[0-9]+",minlength:10, maxlength: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} \ )\ + + [0-9] {3} \- [0-9] {4})

这篇关于jquery验证电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆