JavaScript使用Regex验证电话号码 [英] JavaScript Validate Phone Number Using Regex

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

问题描述

问候溢出者,

我正在尝试编写正则表达式来验证表格##########(10位数)的电话号码)
即这些是有效的情况:1231231234或1111111111.无效的情况将是小于10位或大于10位的数字字符串。

I'm trying to write a regular expression to validate phone numbers of the form ########## (10 digits) i.e. this is these are cases that would be valid: 1231231234 or 1111111111. Invalid cases would be strings of digits that are less than 10 digits or more than 10 digits.

到目前为止我的表达方式是:
\d {10}

The expression that I have so far is this: "\d{10}"

不幸的是,它没有正确验证是否字符串长度超过11位。

Unfortunately, it does not properly validate if the string is 11+ digits long.

有没有人知道要执行此任务的表达式?

Does anyone know of an expression to achieve this task?

推荐答案

您需要使用 ancors ,即

/^\d{10}$/

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

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