Created
May 4, 2013 06:38
-
-
Save reggiegutter/5516498 to your computer and use it in GitHub Desktop.
Regular expression (Regex) para validar números de telefones no formato (XX) XXXX-XXXX para o Brasil.
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 | |
// Função para checar número de telefone | |
function phone_check($phone) | |
{ | |
$exp_regular = '/^\(\d{2}\)\s[2-5]\d{3}\-\d{4}$/'; | |
$ret = preg_match($exp_regular, $phone); | |
if($ret === 1) | |
{ | |
echo 'Número de telefone válido'; | |
return TRUE; | |
} | |
else | |
{ | |
echo 'Número de telefone inválido'; | |
return FALSE; | |
} | |
} | |
// Espero ter ajudado! | |
// Abraço a todos! | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment