i am looking for a phone number verification using php ?
i am looking for a phone number verification using php ?
Forgive me if I am wrong, but this sounds like a homework assignment.
I will say that you will need to use PCRE (Perl Compatible Regular Expressions) for this. In particular you need to use preg_match. I assume that what you are talking about is data submitted via form and you want to check to see if it is a valid phone number as opposed to something made up, similar to detecting whether the email a user submits is a valid email. You probably also want to be sure that the phone number is U.S. based or other.
Last edited by james438; 04-29-2010 at 07:15 AM.
To choose the lesser of two evils is still to choose evil. My personal site
It's fairly easy to do a few ways. I'm sure there's an answer out there on google. Using regex [regular expressions] (described above) is the shortest way to go, or you could just split the phone number at various parts. For example, the area code should be between 100 and 999, so just do that using basic math.
The main problem with this is dealing with lots of varied user input:
###-###-#### or (###) ###-#### or ##########, etc.
One way to do this is to pre-process the values: remove everything that is not a number.
But what about international numbers? What about numbers without an area code? Not allowed? Treated differently?
If you still remove everything that is not a number then you can check the length and go from there: if it's 7 numbers it's a local number; if it's 10 it's got the area code; if there's more, then you get an international number.
But there are also problems with adding the "1" before something like "1-800" vs "800".
Again, I'd just look on google....
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks