[英]Valid UK telephone regex with extensions
I need a regex for php that allows 0-9, the string ext, spaces and + (for UK telephone numbers, ext is for extension). 我需要一个用于php的正则表达式,允许使用0-9,字符串ext,空格和+(对于英国电话号码,ext用于扩展)。 here is my attempt which doesn't work:
这是我的尝试,不起作用:
/^[\d -(ext)]+$/
Any ideas? 有任何想法吗?
You need to take the string out of the character class: 您需要将字符串从字符类中删除:
/^([\d -]+|ext)+$/
To allow ext
just once: 只允许一次
ext
:
/^[\d -]+(ext)?[\d -]+$/
Straight from Google... 直接来自Google ...
Examples of accepted numbers: 可接受数字的示例:
02081234567 02081234567
0208 123 4567 0208 123 4567
020 8123 4567 020 8123 4567
0208 123-4567 0208 123-4567
+44 208 123 4567 +44 208 123 4567
+44 (0) 208 123 4567 +44(0)208123 4567
01234 567 890 01234 567 890
+44 0 1234 567-890 +44 0 1234 567-890
07712 123 456 07712 123 456
Examples of numbers that will not be accepted: 无法接受的数字示例:
020812345678 123456789 07612 123 4567 +33 345 876 1298 020812345678 123456789 07612 123 4567 +33 345 876 1298
/^(((44))( )?|((+44))( )?|(+44)( )?|(44)( )?)?((0)|((0)))?( )?(((1[0-9]{3})|(7[1-9]{1}[0-9]{2})|(20)( )?[7-8]{1})( )?([0-9]{3}[ -]?[0-9]{3})|(2[0-9]{2}( )?[0-9]{3}[ -]?[0-9]{4}))$/
Try these links: 试试这些链接:
http://www.codingforums.com/archive/index.php/t-8307.html http://www.codingforums.com/archive/index.php/t-8307.html
RegEx: Uk Landlines, Mobile phone numbers 正则表达式:英国座机,手机号码
http://regexlib.com/UserPatterns.aspx?authorid=d95177b0-6014-4e73-a959-73f1663ae814 http://regexlib.com/UserPatterns.aspx?authorid=d95177b0-6014-4e73-a959-73f1663ae814
Another programmer I asked directed me to this link to create a telephone validation rule for Codeigniter: 我要求另一个程序员指导我转到此链接,以为Codeigniter创建电话验证规则:
http://codeigniter.com/forums/viewthread/180090/
http://codeigniter.com/forums/viewthread/180090/
This works for me :) 这对我有用:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.