<?php
function checkNumber($phone) {
$verifiedNumber = NULL;
if ( $phone ) {
$f = substr($phone, 0, 1);
if ( $f == "0" ) {
$r = substr($phone, 1, strlen($phone));
$verifiedNumber = "+62$r";
} else if ( $f == "+" ) {
$r = substr($phone, 1, strlen($phone) - 1);
$cc = substr($r, 0, 2);
if ( $cc == "62" ) {
$verifiedNumber = $phone;
}
} else if ( $f == "6" ) {
$cc = substr($phone, 0, 2);
if ( $cc == "62" ) {
$verifiedNumber = "+$phone";
}
}
}
return $verifiedNumber;
}
echo "VALID => " . checkNumber("0811111111112") . "\n";
echo "VALID => " . checkNumber("+62811111111112") . "\n";
echo "VALID => " . checkNumber("62811111111112") . "\n";
echo "INVALID => " . checkNumber("811111111112") . "\n";
echo "INVALID => " . checkNumber("63811111111112") . "\n";
echo "INVALID => " . checkNumber("+63811111111112") . "\n";