Why does this regex not work in PHP?
Posted: Wed Jul 19, 2006 11:58 am
Can someone tell me why the following regular expression doesn't work with
PHP, although it does work with almost every single other regex validator
I've found on the internet, including
http://www.sweeting.org/mark/html/revalid.php and
http://www.koralsoft.com/regextester/ ...??
(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3} ?\d{0,7}
The code I'm using is:
Which, as far as I can see, should work on the supplied dummy phone number.
For some reason it doesn't though, which may just be a problem with my
coding - bear in mind I haven't written anything in PHP for several years so
I'm a bit rusty.
Thanks!
Adam
PHP, although it does work with almost every single other regex validator
I've found on the internet, including
http://www.sweeting.org/mark/html/revalid.php and
http://www.koralsoft.com/regextester/ ...??
(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3} ?\d{0,7}
The code I'm using is:
Code: Select all
<?php
if (ereg('(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3} ?\d{0,7}','020 1234
5678'))
echo "match";
else
echo "no match";
?>For some reason it doesn't though, which may just be a problem with my
coding - bear in mind I haven't written anything in PHP for several years so
I'm a bit rusty.
Thanks!
Adam