Last active
May 31, 2022 16:00
-
-
Save yetimdasturchi/61f15a3545fdc7aab4bf0f4579047ee5 to your computer and use it in GitHub Desktop.
This file contains 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 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