Skip to content

Instantly share code, notes, and snippets.

View kllaudyo's full-sized avatar

Claudio Acioli kllaudyo

View GitHub Profile
var
MNR_ARRAY_TOOLTIPS = document.querySelectorAll("[data-mnr-tooltip]"),
MNR_BODY = document.querySelector("body"),
hasClass = function(element, className) {
for (var i of element.classList)
if (element.classList[i] === className)
return true;
return false;
},
@davidalves1
davidalves1 / formatar_cnpj_cpf.md
Last active May 17, 2024 11:26
Função para formatar CNPJ e CPF, disponível em PHP e JS

PHP

function formatCnpjCpf($value)
{
  $CPF_LENGTH = 11;
  $cnpj_cpf = preg_replace("/\D/", '', $value);
  
  if (strlen($cnpj_cpf) === $CPF_LENGTH) {
    return preg_replace("/(\d{3})(\d{3})(\d{3})(\d{2})/", "\$1.\$2.\$3-\$4", $cnpj_cpf);
  }