File manager - Edit - /var/www/html/portal/public/pmar/js/validacoes.js
Back
function validaCPF(cpf) { if (typeof cpf !== "string") return false; cpf = cpf.replace(/[\s.-]*/igm, ''); if (!cpf || cpf.length != 11 || /^(\d)\1+$/.test(cpf)) { return false; } let soma = 0; let resto; for (let i = 1; i <= 9; i++) soma = soma + parseInt(cpf.substring(i - 1, i)) * (11 - i); resto = (soma * 10) % 11; if ((resto == 10) || (resto == 11)) resto = 0; if (resto != parseInt(cpf.substring(9, 10))) return false; soma = 0; for (let i = 1; i <= 10; i++) soma = soma + parseInt(cpf.substring(i - 1, i)) * (12 - i); resto = (soma * 10) % 11; if ((resto == 10) || (resto == 11)) resto = 0; if (resto != parseInt(cpf.substring(10, 11))) return false; return true; } function validaCNPJ(cnpj) { if (typeof cnpj !== "string") return false; cnpj = cnpj.replace(/[^\d]+/g, ''); if (cnpj.length !== 14) return false; if (/^(\d)\1+$/.test(cnpj)) return false; let tamanho = cnpj.length - 2; let numeros = cnpj.substring(0, tamanho); let digitos = cnpj.substring(tamanho); let soma = 0; let pos = tamanho - 7; for (let i = tamanho; i >= 1; i--) { soma += numeros.charAt(tamanho - i) * pos--; if (pos < 2) pos = 9; } let resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11); if (resultado != digitos.charAt(0)) return false; tamanho = tamanho + 1; numeros = cnpj.substring(0, tamanho); soma = 0; pos = tamanho - 7; for (let i = tamanho; i >= 1; i--) { soma += numeros.charAt(tamanho - i) * pos--; if (pos < 2) pos = 9; } resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11); if (resultado != digitos.charAt(1)) return false; return true; } function monitorCharacterLimit(inputSelector, counterSelector, charLimit) { const input = document.querySelector(inputSelector); const counter = document.querySelector(counterSelector); if (!input || !counter) return; input.addEventListener('input', () => { let currentValue = input.value; const currentLength = currentValue.length; if (currentLength > charLimit) { input.value = currentValue.substring(0, charLimit); } const newLength = input.value.length; counter.textContent = `${newLength}/${charLimit}`; if (newLength === charLimit) { counter.classList.add('text-danger'); } else { counter.classList.remove('text-danger'); } }); }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings