Regular expression. What is wrong?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have to check the phone number. I use some regular expression for
this. The phone number can contain only numbers and characters like
+,-,),( and space. The problem is when I use a Perl-style all works as
intended but when I use a Posix-style I've got the Warning: ereg():
REG_ERANGE and the result is opposite to intended one. What is wrong
in the following?

 <?php
   $test_phone = "8 (044) 419-0567";

   if(preg_match("/^[+]?[\d\-\040\)\(]+$/", $test_phone))
   {
     echo "valid phone<br />";
   }
   else
   {
     echo "not valid phone<br />";
   }

   if(ereg("^[+]?[0-9\-[:space:]\)\(]+$", $test_phone))
   {
     echo "valid phone<br />";
   }
   else
   {
     echo "not valid phone<br />";
   }
 ?>

-- 
Best regards,
 Kostyantyn Shakhov mailto:shakhov@xxxxxxxxxxxxxxxx

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux