function cpfValidation(strCPF) { strCPF = strCPF.trim(); strCPF = strCPF.replace(/\D+/g, ''); if (strCPF.length != 11) return false; const identical = Array(12).join(strCPF.substring(0, 1)); if (strCPF == identical) return false; let Soma; let Resto; Soma = 0; for (i=1; i<=9; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (11 - i); Resto = (Soma * 10) % 11; if ((Resto == 10) || (Resto == 11)) Resto = 0; if (Resto != parseInt(strCPF.substring(9, 10)) ) return false; Soma = 0; for (i = 1; i <= 10; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (12 - i); Resto = (Soma * 10) % 11; if ((Resto == 10) || (Resto == 11)) Resto = 0; if (Resto != parseInt(strCPF.substring(10, 11) ) ) return false; return true; } function validateCPF(inputId, errorId, validEmpty = false) { const cpf = document.getElementById(inputId).value; if (validEmpty && cpf === '') { return true; } const cpfError = document.getElementById(errorId); if (!cpfValidation(cpf)) { cpfError.textContent = "CPF inválido."; return false; } else { cpfError.textContent = ""; return true; } } function todayString() { let today = new Date(); let dd = today.getDate(); let mm = today.getMonth() + 1; //January is 0! const yyyy = today.getFullYear(); if (dd < 10) { dd = '0' + dd; } if (mm < 10) { mm = '0' + mm; } today = yyyy + '-' + mm + '-' + dd; return today; } const today = todayString(); const nascimentos = document.getElementsByClassName("nascimento"); for (let i = 0; i < nascimentos.length; i++) { nascimentos[i].setAttribute("max", today); nascimentos[i].setAttribute("min", "1920-01-01"); // nascimentos[i].max = new Date().toLocaleDateString('fr-ca'); }