how to validate mobile number in php?

how to validate mobile number in php – Php Validate Phone Number using pattern, Regular Expression Mobile Number Validation in PHP.

$phone = '000-0000-0000';

if(preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $phone)) {
  // $phone is valid
}

how to validate mobile number in php?

Mobile valid pattern

$mob="/^[1-9][0-9]*$/"; 

How to validate phone number in PHP?

Example

function validate_phone_number($phone)
{

     $filtered_phone_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);

     $phone_to_check = str_replace("-", "", $filtered_phone_number);

     if (strlen($phone_to_check) < 10 || strlen($phone_to_check) > 14) {
        return false;
     } else {
       return true;
     }
}

how to validate phone number in php procedural programming?

Example

if((preg_match("/[^0-9]/", '', $str)) && strlen($str) == 10)
{
echo "Invalid phone number
}

Mobile number validation pattern in PHP

index.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);
 
?>

How To Validation Phone Number Using PHP?

I hope you get an idea about how to validate mobile number in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.