Last active
September 24, 2016 03:47
-
-
Save khanhicetea/9058eef0acced98d82c608eddd0bb106 to your computer and use it in GitHub Desktop.
Check valid vietnamese mobile phone number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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