Search code examples
phpisnumeric

Check Moblie Number or Not in PHP String


Iam New in PHP . I Know How to Check a String number or Not using is_numeric but I want Check Mobile Number add + in my case

$mobile = "+15666886345" ;
if($mobile)  {
  //  Valid  Mobile Number
} 
else   {
// Not Valid Mobile Number
}

How to Check this Case


Solution

  • You can use php preg_match() function to match the string as like below

    if(!preg_match('/^[0-9 +-]*$/', $mobile)){
         //  Valid  Mobile Number
    }else{
         // Not Valid Mobile Number
    }