基于GB且仅数字电话号码的正则表达式 [英] Regular expression for GB based and only numeric phone number

查看:78
本文介绍了基于GB且仅数字电话号码的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个仅允许数字电话号码(例如1234567890)和GB格式号码(例如123-456-7890)的正则表达式代码。

I want a regular expression code which allows only numeric phone number (e.g 1234567890) as well as GB format number (e.g 123-456-7890).

当前,我正在使用下面的正则表达式,该表达式只允许使用GB电话号码

Currently I am using below regular expression which only allows GB phone number

/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/ 

我需要帮助,也只允许使用数字。 / p>

I need help to allow only numeric number also.

推荐答案

有一些英国电话号码正则表达式此处

There are some UK phone number regular expressions here.

该页面中评分最高的一个是:

The most highly rated one from that page is:

^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$

它被描述为:

Matches     +447222555555   | +44 7222 555 555 | (0722) 5555555 #2222
Non-Matches (+447222)555555 | +44(7222)555555  | (0722) 5555555 #22

我个人不会在电话号码上使用严格的正则表达式,除非它是绝对需要拥有用户的真实电话号码以进行身份​​验证或涉及付款的内容。电话号码有很多变化,有些用户甚至可以将Skype用作他们的主要电话,并且通过进行验证,您就可以阻止/挫败用户。

Personally I would not put a strict regex on a phone number unless it is absolutely required to have the users actual phone number for identity verification or something involving payments. There are lots of variations of phone numbers, some users could even use Skype as their primary phone, and by putting a validation on you're just going to block/frustrate users.

还请注意,您输入的英国格式有误,英国电话号码应包含11位数字,并且通常采用(01234)123123格式-我们从不使用破折号,并且第一个数字应始终为0。

Also note you have got the UK format wrong, UK phone numbers should contain 11 digits and are normally in the format (01234) 123123 - we never use dashes and first number should always be a 0.

这篇关于基于GB且仅数字电话号码的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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