Skip to content

Instantly share code, notes, and snippets.

View thbighead's full-sized avatar

Thales Nathan thbighead

  • Brazil, Rio de Janeiro
View GitHub Profile
@thbighead
thbighead / validar_cpf.php
Created July 7, 2019 16:45 — forked from rafael-neri/validar_cpf.php
Validar CPF em PHP (Completo)
<?php
function validaCPF($cpf) {
// Extrai somente os números
$cpf = preg_replace( '/[^0-9]/is', '', $cpf );
// Verifica se foi informado todos os digitos corretamente
if (strlen($cpf) != 11) {
return false;
<?php
function validar_cnpj($cnpj)
{
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
// Valida tamanho
if (strlen($cnpj) != 14)
return false;