Client LoginView your Shopping CartHelp & Frequently Asked QuestionsEmail Us
Home Services Portfolio Web Design Pricing Dreamweaver Templates Web Applications Free Tutorials About Contact Us
Services > CSS Web Design | Professional Logo Design | ASP.net, ASP & PHP Programming | Flash Animation & Programming | Website Maintenance
Portfolio > Web Design Portfolio | Web Programming Portfolio | Logo Design Portfolio | Web Design Pricing > Custom Web Design | Logo Design | Business Card Design
Web Design Guide > Website Design w/ Dreamweaver & Fireworks | Fireworks CS4 Cool Features | Photo Effects | Text Effects | Graphic Design Ideas | Web Design Ideas
Website Navigation Ideas | CSS Styles Tutorial | Dreamweaver Template | Server Side Includes | Flash Tutorials > Flash Effects | Flash Sound Button | Sound On/Off Button
Flash Preloader | Import External Data | Promotion > SEO Tips | Google Tips & Page Rank | JavaScript > Date Validation | Email Validation | Phone Validation | Tip Boxes

International Phone Number Validation in PHP

In this tutorial you will learn about getting International phone numbers and validating them 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.

Example:

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:

Use the sample code given below in your test page and try it yourself.

Sample PHP Code:

<?php
//Check whether the submission is made
if(!isset($_POST["hidSubmit"])){

//Declarate the necessary variables
$intisd="";
$intccode="";
$intphone="";
DisplayForm();
}
else{

//Assign the entered values to variables for validation
$intisd=$_POST["txtisdcode"];
$intccode=$_POST["txtcitycode"];
$intphone=$_POST["txtphone"];

//The entered value is checked for proper format
if(substr_count($intisd,"+")>0){
if(strpos($intisd,"+")==0)
$intisd=substr($intisd,1,strlen($intisd));
}
$result=ereg("^[0-9]+$",$intisd,$trashed);
$result=ereg("^[0-9]+$",$intisd,$trashed);
if(!($result)){echo "Enter Valid ISDCODE";}
$result=ereg("^[0-9]+$",$intccode,$trashed);
if(!($result)){echo "Enter Valid CITY CODE";}
$result=ereg("^[0-9]+$",$intphone,$trashed);
if(!($result)){echo "Enter Valid Phone Number";}
DisplayForm();
}

//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

HTML CODE

Refer: Explanation of Code

Absolutely FREE Web Templates
Check out these quality free web templates and download them without any registration or sign-up!

FREE Web Design Guide
From web design tips & ideas to HTML, CSS Styles, Fireworks & Dreamweaver you'll find all you need to know about effective web site design right here!

Quality Dreamweaver Templates
Professional quality dreamweaver templates in over 20 categories, starting at just $9.95! Instant download & easy customization

Beauty Templates | Business Templates | Christian Templates | CSS Templates | Education Templates | Family Templates | Flash Templates | Free Dreamweaver Templates
Food Templates | General Templates | Government Templates | Health/Medical Templates | Hi-Tech Templates | Kids/Childcare Templates | Low-cost Budget Templates
Personal Templates | Pets Templates | Photography Templates | Profession Templates | Real Estate Templates | Sports Templates | Telecom Templates | Travel Templates
Free Tutorials > Web Design Tutorials | CSS Web Design | Fireworks Tutorials | Dreamweaver Tutorials | Flash Tutorials | SEO Tutorials | Javascript Tutorials | PHP Tutorials