I suggest you validate phone number by just stripping non-digits. And verify by sending a confirmation code as sms. I validate subscribers phone numbers using twilio. I send a code number to that number and user have to enter it to verify. Thats the verification process. And before inserting it into database I use following code.
$dnum = preg_replace('/\D+/','', $num);
if(preg_match('/^[\d()\s-]+$/', $num)
&& in_array(strlen($dnum), array(7,10,11,13)){
// valid phone number
}else{
// invalid phone number
}
What this code do is,
- Strips all the non-digit characters
- Check the allowed characters. Only
()-
are allowed as non-digit characters.
- Check the length after stripping. It should be either 7 or 10 or 11 or 13.