Mobile phone number validation regex in php - Regex for Indian Phone Numbers
Posted by Raj
Mobile phone number validation regex in php - Regex for Indian Phone Numbers
In this article,I will explain how to validate Mobile phone number using regex in php.I have written simple php script using regular expression to validate all mobile phone numbers.
e.g.+910000000000,0000000000,910000000000,+91 0000000000,+91-0000000000...etc
PHP regular expressions help your application to validate Mobile Numbers,Emails,phone numbers,..etc.
The first sign (^) represents that it is the beginning of the string and ($) represents the end of the string.
I have a function which checks to see if a Indian telephone/Mobile number is valid or not.
Example: Regular Expression Mobile Number Validation in PHP
<?php
$mobile="910000000001";
function phoneNumbervalidation($mobile)
{
if(preg_match('/^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1})?([0-9]{10})$/', $mobile,$matches)){
print_r($matches);
return true;
}
else
return false;
}
phoneNumbervalidation($mobile);
?>
I hope above example will help you to validate Indian Mobile numbers.You can refer above Regular expressions to validate international phone numbers.
In this article,I will explain how to validate Mobile phone number using regex in php.I have written simple php script using regular expression to validate all mobile phone numbers.
e.g.+910000000000,0000000000,910000000000,+91 0000000000,+91-0000000000...etc
PHP regular expressions help your application to validate Mobile Numbers,Emails,phone numbers,..etc.
The first sign (^) represents that it is the beginning of the string and ($) represents the end of the string.
I have a function which checks to see if a Indian telephone/Mobile number is valid or not.
Example: Regular Expression Mobile Number Validation in PHP
<?php
$mobile="910000000001";
function phoneNumbervalidation($mobile)
{
if(preg_match('/^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1})?([0-9]{10})$/', $mobile,$matches)){
print_r($matches);
return true;
}
else
return false;
}
phoneNumbervalidation($mobile);
?>
I hope above example will help you to validate Indian Mobile numbers.You can refer above Regular expressions to validate international phone numbers.
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Indian phone number validation,
Mobile phone number validation regex php
.You can leave a response, or trackback from your own site.
November 10, 2014 at 9:19 PM
by adding some changes to your regex expression you can add more flexibility related to the phone number format.
$result = preg_match('/^(((\+|00){1}91(\s|\-){0,1})?([0-9]{0,6}(\s|\-){0,1})?)?([0-9]{8,10})$/', $mobile,$matches);
Also, phone number can contain white space as delimiter between country code and phone number / country code, region prefix and phone number / region prefix and phone number (last two are applied to the landlines).
The result will look like:
Matches: Array (
[0] => +91 123456-0123456789
[1] => +91 123456-
[2] => +91
[3] => +
[4] =>
[5] => 123456-
[6] => -
[7] => 0123456789
)