Posted inphp / Programming

Format Phone Number using PHP

Today, We want to share with you php phone number format.In this post we will show you php international phone number validation, hear for PHP Mobile number formatting we will give you demo and example for implement.In this post, we will learn about How To Allow Only 10 Digit Mobile Number Validation Using Javascript With Jquery with an example.

php format phone numbers

Below is a tiny and simple PHP function that will take any 10 digit mobile number and convert it into the following moblie or phone format: 982-062-41**.

function phone_number_format($mobile_number) {
  //here verify and simple Allow only number Digits, remove all any types of other characters.
  $mobile_number = preg_replace("/[^\d]/","",$mobile_number);
 
  // get mobile_number length.
  $length = strlen($mobile_number);
 
 // if mobile_number = 10
 if($length == 10) {
  $mobile_number = preg_replace("/^1?(\d{3})(\d{3})(\d{4})$/", "$1-$2-$3", $mobile_number);
 }
  
  return $mobile_number;

}

I hope you get an idea about php validate phone number.
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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype