English 中文(简体)
网址上电话号码的定期表述
原标题:regular expression for phone number in php

我正在对电话号码使用zen式认证。 我想,用户应当用这些格式进入电话号码:

"+91-151-1234567", "01234567891", "+912345678901"

也就是说,使用这一定期表述:

"^(?:+?([0-9]{3}))?[-. ]?(?([0-9]{3}))?[-. ]?([0-9]{10})[-. ]$"

but it is not working. it is generating error :

Fatal error: Uncaught exception Zend_Validate_Exception with message Internal error matching pattern ^(?:+?([0-9]{3}))?[-. ]?(?([0-9]{3}))?[-. ]?([0-9]{10})[-. ]$ against value +91-151-3297154 in /var/www/html/allindiazend/library/Zend/Validate/Regex.php:117 Stack trace: #0 /var/www/html/allindiazend/library/Zend/Validate.php(98): Zend_Validate_Regex->isValid( +91-151-3297154 )

1 /var/www/html/allindiazend/library/Zend/Validate.php(98):

Zend_Validate->isValid(+91-151-3297154)

2 /var/www/html/allindiazend/library/Zend/Filter/Input.php(932):

Zend_Validate->isValid(+91-151-3297154)

3 /var/www/html/allindiazend/library/Zend/Filter/Input.php(800):

Zend_Filter_Input->_validate Rule(Array)

4 /var/www/html/allindiazend/library/Zend/Filter/Input.php(688):

Zend_Filter_Input->_validate() #5 /var/www/html/allindiazend/library/Zend/Filter/Input.php(430): Zend_Filter_Input->_process() #6 /var/www/html/allindiazend/application/controllers/StaticController.php(148): Zend_Filter_Input->isValid() #7 /var/www/html/allindi in /var/www/html/allindiazend/library/Zend/Validate/Regex.php on line 117

任何人都能够帮助我这样做。

thank you in advance.

最佳回答

这一表述将与你的三个例子一致:

+?([0-9]{2})-?([0-9]{3})-?([0-9]{6,7})
问题回答

你们的哪一部分是 matching子,但我只是测试了我所写的另一种版本,似乎为你的所有例子工作:

^(+d{12}|d{11}|+d{2}-d{3}-d{7})$

我不广泛检查所有允许的格式,而是允许任何形式。 您可以将其转换成一种单一的格式(不计邮资和括号)来检查你们的希望,以同样的方式储存每份电话号码,以便你也能轻易检索。

如果你以这种方式解决你的问题,你的接口更方便用户,更方便地增加更多的检查,你储存的电话号码更便于其他应用。

如果我制作一个文件箱,摘录在一页上的所有电话号码。

The numbers may be written in different formats such as: 0039024343333 +39024343333 (0041) 91 999 11 11 +41 (0) 91 999 11 11 0919991111 091 99 911 11 +1 123 344 2244 5 123-344-2244-5 etc..

我已尝试过这一文字,但只是部分工作:

GetPhoneNumber function ($ txt) {
$ regexp =  / ([+   s]) {1,3} ([0-9   s] {2,5}) -? ([0-9   s] {2,5}) -? ([0-9   s] {2,20}) /  ;

preg_match_all ($ regexp, $ txt, $ m);


return isset ($ m [0])? $ m [0]: array ();
}

$ fulltxt = file_get_contents ( http://wiki.wikimedia.it/wiki/Contatti );
$ phonenumber = GetPhoneNumber ($ fulltxt);
print_r ($ phonenumber);




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签