Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Last active May 31, 2022 16:00
Show Gist options
  • Save yetimdasturchi/61f15a3545fdc7aab4bf0f4579047ee5 to your computer and use it in GitHub Desktop.
Save yetimdasturchi/61f15a3545fdc7aab4bf0f4579047ee5 to your computer and use it in GitHub Desktop.
<?php
function clear_phone($number)
{
return preg_replace('/\D/', '', $number);
}
function validate_phone($number)
{
return boolval( preg_match("/^998(90|91|93|94|95|97|98|99|33|88)[0-9]{7}$/", $number ) );
}
function format_phone($number)
{
return preg_replace( '/^(998)(90|91|93|94|95|97|98|99|33|88)([0-9]{3})([0-9]{2})([0-9]{2})$/', '+$1 ($2) $3-$4-$5', $number);
}
var_dump( validate_phone( '998909999999' ) );
var_dump( format_phone( '998909999999' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment