带模式的 HTML5 电话号码验证 [英] HTML5 phone number validation with pattern

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

问题描述

我正在使用 HTML5 表单验证来验证来自印度的电话号码.

I'm using HTML5 form validation to validate phone numbers from India.

来自印度的电话号码有 10 位数字,以 7、8 或 9 开头.

Phone numbers from India are 10 digits long, and start with 7, 8, or 9.

例如:

  1. 7878787878
  2. 9898989898
  3. 8678678878

这些电话号码是有效的,但是

These phone numbers are valid, but

  1. 1212121212
  2. 3434545464
  3. 6545432322

无效.

建议一种可以检测有效印度电话号码的模式.

Suggest a pattern that can detect valid India phone numbers.

到目前为止,我的模式是 [0-9]{10},但它不会检查第一个数字是 7、8 还是 9.

So far, my pattern is [0-9]{10}, but it doesn't check if the first digit is 7, 8, or 9.

推荐答案

这个怎么样?/(7|8|9)d{9}/

首先查找 7 或 8 或 9,然后是 9 位数字.

It starts by either looking for 7 or 8 or 9, and then followed by 9 digits.

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

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