fork download
  1. <?php
  2.  
  3. $testes = [
  4. "000.000.000-00",
  5. "00000000000",
  6. "000",
  7. "usuario@servidor.com"
  8. ];
  9.  
  10. foreach ($testes as $teste) {
  11. if (preg_match("/^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/", $teste)) {
  12. echo "É CPF", PHP_EOL;
  13. } else {
  14. echo "É e-mail", PHP_EOL;
  15. }
  16. }
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
É CPF
É CPF
É e-mail
É e-mail