Created
May 4, 2013 05:53
Revisions
-
reggiegutter created this gist
May 4, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <?php // Função para checar número de telefone function phone_check($phone) { $exp_regular = '/^(\(11\) (9\d{4})-\d{4})|((\(1[2-9]{1}\)|\([2-9]{1}\d{1}\)) [5-9]\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; } } // Essa expressão é feita mais para telefones celulares. // Você pode adicionar suporte para todos os números de telefone, ou criar outro regex com base nesse. // Se alguém encontrar uma forma de melhorá-lo ou se alguma coisa estiver errada, favor informa! // testes preg_match($exp_regular, '(11) 92222-2222'); // OK preg_match($exp_regular, '(12) 8222-2222'); // OK preg_match($exp_regular, '(11) 82222-2222'); // NOT OK preg_match($exp_regular, '(12) 92222-2222'); // NOT OK preg_match($exp_regular, '(11) 3222-2222'); // NOT OK // Espero ter ajudado! // Abraço a todos! ?>