PHP Tutorials

Phone No Validation

International Phone Number Validation in PHP

International Phone Number Validation in PHP

In this tutorial you will learn about validation of International phone numbers using PHP programming. When phone numbers are obtained from users using form fields, its a good practice to validate the phone number value using PHP code. The following example explains how it can be done for International Phone Numbers.


International Phone Number Validation

Enter your Phone Number Country Code
Area Code
Phone Number

For the above input, the error message generated is as shown below:

  • Error Enter valid ISD Code
  • Error Enter valid Area Code
  • Error Enter valid Phonenumber.
Use the sample code given below in your test page and try it yourself.

Sample PHP Code:

//Check whether the submission is made

//Declarate the necessary variables

//Assign the entered values to variables for validation

//The entered value is checked for proper format
if(!($result)){echo "Enter Valid ISDCODE";}
if(!($result)){echo "Enter Valid CITY CODE";}
if(!($result)){echo "Enter Valid Phone Number";}

//User-defined Function to display the form in case of Error
function DisplayForm(){
global $intisd,$intccode,$intphone;


HTML code for the form follows..

Cut 'n' Paste Code for the above Example


Refer: Explanation of Code

Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!