0

Was curious how to validate a phone number input field? Currently I am requiring that the phone # format be (5555555555) so that i can simply say if(is_numeric($phone_num))
so then when i retrieve it from DB i must manipulate the string to format it properly"(555)555-5555" But i was thinking it would be easier if there was a way to just validat the proper chars "(), and -" so that they can just type it in correctly and i can make sure they did so. Just wasn't sure how to validate with it having those extra chars "().and -" in the field. thanks for any input in advance, much appreciated. :)

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by fuston05
0

$phonenum=preg_replace("/[^0-9]/", "", $_POST);

it'll leave only the numeric numbers in the string

0

what i am hoping to achieve here is that they are forced to enter the number properly "555-555-5555". However.. if i cannot force them to enter it that way, then i would like them to enter "#'s only", and then when I query it I would like to re format it so it appears properly to me with the "-"'s. I am new to php reg expressions. I have been reading up on them and trying them out for this, but still no luck yet, I appreciate all your advise. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.