Tutorials

Article Content:How to validate phone number using PHP

How to validate phone number using PHP

My client asked me to develop E-commerce website, visitors will have the ability to register and add products to the cart then place order.

Register validation will be through sms validation message,and this the case , how to avoid fake mobile numbers ? ,How to reduce the failure of inserting mobile numbers through international registration ,so i think to look at already solutions that have fixed this issues ,one of them is Uber

If you have ever used Uber you may noticed that while registering , you should use your country without need to fill country call key ,then when you do that ,the placeholder for mobile example will appear in the mobile  input to guide you how exactly you should write your mobile number , finally when write and submit it will validate the written number ,if it's okay you will receive a validation SMS ,else you will see an error message that lead you to fix your mobile number because it's not correct, you can take a look at this process below.

But the main question is ,how to implement something like this with PHP,so i made quick survey and i found there are many cool APIs outhere with a good techniques to implement mobile validation , but the bad news is that many of them are free limited then you should paid,my client want a free solution without the hassle of monthly payment because it's not suitable solution for startups and small companies.

So the next search should be on this target :

Find a good PHP library that do the job,and i found it , it was called : libphonenumber ,and the cool it has created by google ,and supported multiple programing languages and platforms like c++ , Java, JavaScript..etc , and the awesome PHP community  make an great implementation for that library with pure language , symfony and laravel

For that I thought to create another one for codeigniter developers and make a tutorial on how to use it with pure php

So If you're interested to learn in the video below you have step by step instructions ,or if you just want the countries list just download it

also to integrate this library with codeigniter download the codeigniter example below and use this instructions

1- add the library into libraries directory
2- add valid_mob into third_party directory
3- copy is_valid_mobile function into your controller

 



Leave a Reply

Your email address will not be published.


Notify me of followup comments via e-mail.
You can also Subscribe without commenting.