Skip to content

Instantly share code, notes, and snippets.

@iamshanto
Created September 15, 2018 11:16
Show Gist options
  • Save iamshanto/a0b69c51ff63b4d2b58618249f384e7f to your computer and use it in GitHub Desktop.
Save iamshanto/a0b69c51ff63b4d2b58618249f384e7f to your computer and use it in GitHub Desktop.
function sanitizeMobileNumber($mobile, $prefix = '0')
{
$mobile = ltrim(trim($mobile), '.+80');
$mobile = str_replace([' ', '-', '.', '+'], '', $mobile);
$mobile = strrev(substr(strrev($mobile), 0, 10));
if (!in_array(substr($mobile, 0, 2), ['15', '16', '17', '18', '19', '13']) || strlen($mobile) != 10) {
return null;
}
return $prefix.$mobile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment