View Single Post
  #3 (permalink)  
Old 09-01-2008, 01:15 PM
chili5's Avatar   
chili5 chili5 is offline
Code Warrior
 
Join Date: Mar 2008
Age: 16
Posts: 3,930
Last Blog:
DWITE 2
Credits: 0
Rep Power: 35
chili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to allchili5 is a name known to all
Default Re: Phone number regexp

I could do that, but I didn't think of this before, just check the phone number against two regular expressions (one with the area code, and one without it) like so:

PHP Code:
if (preg_match("/[0-9]{3}?-[0-9]{3}-[0-9]{4}/""555-555-5555") || preg_match("/[0-9]{3}?-[0-9]{4}/","555-5555")) {
    echo 
"Valid phone number.<br />";
} else {
    echo 
"Invalid phone number.<br />";

I think that is more simple, and it still does work.
__________________
I've found time can heal most anything
And you just might find who you're supposed to be
I didn't know who I was supposed to be at fifteen.
~ Taylor Swift
Reply With Quote