Jump to content

[SOLVED] phone number validation


verN

Recommended Posts

hiyya all,

I wanted to know how to validate the phone number entered by the user. In my database phone number is defined as int(3) unsigned. Would it be best to use php and use regular expersssions or use javascript. Any code would be beneficial

 

 

$phone = trim($_POST['phone']);

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/41002-solved-phone-number-validation/
Share on other sites

how would i use the isNumeric value could you show the code for this

 

would it be  if(!empty){

                isNumeric(phoneNo)

                return true;

                } else {

                return false;

                error[]=You need to enter numerc values;

 

 

thanks

 

Use this function,

Code:

if(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone)) {
echo "valid phonenumber";
}
else {
echo "invalid phonenumber";
}

 

[0-9] This will check that the entered thing is number,

{3} this will check the expression for 1st 3 numbers and so on for others.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.