Skip to content

Instantly share code, notes, and snippets.

@reggiegutter
Created May 4, 2013 06:38
Show Gist options
  • Save reggiegutter/5516498 to your computer and use it in GitHub Desktop.
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.
<?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