| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
I like Iced Tea
|
PHP Phone Number Validation
How do you incorporate this PHP Code:
PHP Code:
is it something like this??? PHP Code:
Is that how you do it? this is to validate a phone number 000-000-0000. |
|
|
|
|
|
#2 (permalink) |
|
I like Iced Tea
|
ALSO! how do you validate a text field that has to be either a valid phone number or can be left empty.??? soo if the person does not input a phone number in then it will not validate it as being invalid. But if the person does, it has to be a valid phone number ! Last edited by Maciek : 19-12-2007 at 22:21. |
|
|
|
#3 (permalink) |
|
Senior Member
|
from php.net PHP Code:
so then your code would be: PHP Code:
i'm just guessing as i'm too lazy to test it but you should be able to get going from that. |
|
|
|
#10 (permalink) |
|
I like Iced Tea
|
When the whole code above is incorporated, it shows an error. I think its because I us "else if". PHP Code:
this has the code in it. What am i doing wrong? all this code is off a turtorial. so im not sure what the problem is. |
|
|
|
#12 (permalink) |
|
I like code.
|
You are most likely getting errors by using else if then going to if and else and back to else if in this section. PHP Code:
You'll have to change it to something like. PHP Code:
If that is not the error that you are getting it will most likley pop up latter. Code { for thought }
"My programs never have bugs, they just develop random features." |
|
|
|
#14 (permalink) |
|
I like code.
|
change this PHP Code:
to this PHP Code:
Also I added the /s because without using them it was giving me an error and it was the quickest way to fix the error. Code { for thought }
"My programs never have bugs, they just develop random features." |
|
|
|
#15 (permalink) |
|
Grumpy old man
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
|
As cborrow pointed out, the order of a branching if statement goes as follows... if else if (as many times as you want) else Theoretically, if you want maximum efficiency, especially in an interpreted language, the if(...) should be the most likely condition so that the test is satisfied and the code immediately branches. The else at the end is a catch all in case none of the other conditions prove to be true. |
|
|
|
#18 (permalink) |
|
I like Iced Tea
|
Thanks Cborrow!!! i really appreciate your you help! it all works now. Also someone mentioned that if someone doesnt put 123-123-1231 but puts 123 123 1231 without the "-" then it would just add the "-" ... could someone many get me a link to a turtorial that could help me on this? thanks for everything guys |
|
|
|
#19 (permalink) | |
|
Grumpy old man
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
|
Quote:
Absolutely - think about it in plain English. For example, choosing where to eat. If you want to eat Pasta, go to Luigi's Restaurant. Else, if you want to eat Noodles, go to the Panda Garden. Else, if you want to have Sushi, go to Benihana. Else, go to McDonalds. The final else is the 'last resort' if none of the other options are right. |
|
|
|
|
#20 (permalink) | |
|
Grumpy old man
Join Date: Oct 2007
Location: North Japan
Posts: 1,696
|
Quote:
I don't have a tutorial to link you to, but this should be all you need to know: str_replace("-", " ", $htelephone); // replaces a dash with a space in the string $htelephone str_replace(find_this, replace_with_this, string_to_search); If you want to use regular expressions, use preg_replace() instead. |
|
|
![]() |