基于英国的正则表达式,只有cakephp中的数字电话号码 [英] Regular expression for UK based and only numeric phone number in cakephp

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

问题描述

我想要一个只允许数字电话号码(例如1234567890)以及英国格式号码(例如123-456-7890)的正则表达式代码。





目前我使用的正则表达式只允许英国电话号码

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

我需要帮助只允许数字。 / p>

谢谢。

解决方案

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



该页面是:

  ^(((\ + 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 \\ \ d {2} | \(?0 \d {2} \)?)\s?\d {4} \s?\d {4})) \#(\ d {4} | \d {3}))?$ 

它描述为:

 匹配+447222555555 | +44 7222 555 555 | (0722)5555555#2222 
不匹配(+447222)555555 | +44(7222)555555 | (0722)5555555#22

我个人不会对电话号码使用严格的正规表达式,除非绝对需要有用户实际电话号码进行身份验证或涉及付款的事情。有很多电话号码的变化,一些用户甚至可以使用Skype作为主要手机,并通过验证你只是阻止/挫败用户。



请注意,您的英国格式错误,英国电话号码应包含11个数字,通常格式为(01234)123123 - 我们永远不要使用破折号,第一个数字应始终为a 0。


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

this expression must have to work for both conditions.

Currently i am using below regular expression which only allows UK phone number

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

i need help to allow only numeric number also.

Thanks.

解决方案

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}))?$

It is described as:

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

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.

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.

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

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