Skip to content

Instantly share code, notes, and snippets.

@khanhicetea
Last active September 24, 2016 03:47
Show Gist options
  • Save khanhicetea/9058eef0acced98d82c608eddd0bb106 to your computer and use it in GitHub Desktop.
Save khanhicetea/9058eef0acced98d82c608eddd0bb106 to your computer and use it in GitHub Desktop.
Check valid vietnamese mobile phone number
<?php
function format_vn_phone($phone)
{
$phone = preg_replace('/[^0-9]/', '', $phone);
if (strlen($phone) > 10 && substr($phone, 0, 2) == '84') {
$phone = substr($phone, 2);
}
return substr(empty($phone) || $phone[0] == '0' ? $phone : '0'.$phone, 0, 11);
}
function is_valid_phone($phone)
{
$phone = format_vn_phone($phone);
$match = preg_match('/09\d{8}|01(20|21|22|23|24|25|26|27|28|29|62|63|64|65|66|67|68|69|86|88|99)\d{7}/', $phone);
return $match ? $phone : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment