ereg for phone number format #*$!-xxx-xxx not working
stidj
3:33 pm on Aug 2, 2005 (gmt 0)
Hi guys
I have tried using "[0-9]{3}-[0-9]{3}-[0-9]{4}" but this does not work as intended and seems to allow nearly anything to match it for some reason.
Does anyone know how to match it for only numbers in format #*$!-xxx-xxxx?
Thanks
vincevincevince
3:39 pm on Aug 2, 2005 (gmt 0)
I think the - between needs escaping to \-
[0-9]\-[0-9] etc
stidj
5:02 pm on Aug 2, 2005 (gmt 0)
I'll give that a try later on (all the examples I've seen don't escape but then again all of the example code doesn't work as the tutorials claim) :)
Thanks vince.
dreamcatcher
6:34 pm on Aug 2, 2005 (gmt 0)
Is this any good?
if (ereg("^[0-9)( - ]{7,20}(([xX] ¦ (ext) ¦ (ex))?[ -]?[0-9]{1,7})?$", $phone))
{
//valid phone no
} else {
//not valid
}
dc
stidj
12:48 am on Aug 5, 2005 (gmt 0)
Unfortunately both ideas don't work for some reason.
I'm using PHP 4.3.11 might there an issue with it?
coopster
1:00 am on Aug 5, 2005 (gmt 0)
stidj,
It may help if you show us what the string looks like that you are searching as well as your ereg line of code. For example, is your string just the phone number or is it embedded in a longer string of data?
stidj
2:24 am on Aug 5, 2005 (gmt 0)
Here it is. I have tried other combinations such as a "^" at the beginning and a "$" at the end