I tried to
Code: Select all
if(!eregi('^[0-9-] +', $phone))
array_push($mistake, 'Invalid Phone number');Moderator: General Moderators
Code: Select all
if(!eregi('^[0-9-] +', $phone))
array_push($mistake, 'Invalid Phone number');WOW, that is sooo cheating.Kieran Huggins wrote:http://regexlib.com/Search.aspx?k=phone
Why not let the user choose the format he wishes to use for phone input, be it dashes, spaces, slashes, dots, whatever. Let your script clean it up and then just check the numbers. I mean, you don't want to go show errors like "Your phone number must not contain spaces, please remove them", do you?shivam0101 wrote:I want to validated phone number. It is in the pattern, digits 0-9 and - (hyphen can be present)
Code: Select all
// Clean phone number
$phone = preg_replace('/\D+/', '', $_POST['phone']);