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. :)

On PHP level you can use regular expressions. Look up the manual for the preg_... functions.

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

it'll leave only the numeric numbers in the string

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.