Improve validation and formatting for 0303 and 0505 phone numbers

This commit is contained in:
Kijin Sung 2019-05-13 15:34:09 +09:00
parent 1d22aa9a44
commit d873196aa8
2 changed files with 18 additions and 1 deletions

View file

@ -47,7 +47,14 @@ class Korea
default:
if (substr($num, 0, 4) === '0303' || substr($num, 0, 3) === '050')
{
return substr($num, 0, 4) . '-' . substr($num, 4, 3) . '-' . substr($num, 7);
if (strlen($num) === 12)
{
return substr($num, 0, 4) . '-' . substr($num, 4, 4) . '-' . substr($num, 8);
}
else
{
return substr($num, 0, 4) . '-' . substr($num, 4, 3) . '-' . substr($num, 7);
}
}
else
{
@ -77,6 +84,10 @@ class Korea
{
return true;
}
if (preg_match('/^0(?:303|505)[2-9][0-9]{6,7}$/', $num))
{
return true;
}
return false;
}