Home > Article > Backend Development > Phone Number Mobile Number Regular Expression Example_PHP Tutorial
Phone number mobile phone number regular expression example
Input 13875998850
Output valid contact information
Enter 0136986+9557
There is a problem with outputting contact information
function funcPhone( $str)//Telephone number regular expression try
{
return (preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3 })|0d{2,3}-)?[1-9]d{6,8}$/",$str))?true:false;
}
function funcMtel($ str)//Mobile phone number regular expression try
{
return (preg_match("/(?:13d{1}|15[03689])d{8}$/",$str))?true: false;
}
if( $_POST)
{
if( funcPhone( $_POST['url'] ) || funcMtel( $_POST['url'] ) )
{
echo 'Valid contact information';
}
else
{
exit('There is a problem with the contact information');
}
}
?>