Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1x 12x 9x 12x 5x 5x 12x 5x 12x 12x 5x 12x 5x 12x 5x 5x | export function isCPF(cpf: string | null | undefined): boolean {
if (!cpf) return false
cpf = cpf.replace(/[.-]/g, '')
if (cpf.length !== 11 || /^(\d)\1{10}$/.test(cpf)) return false
let sum = 0,
rest
for (let i = 1; i <= 9; i++) sum += parseInt(cpf[i - 1]) * (11 - i)
rest = (sum * 10) % 11
if (rest === 10 || rest === 11) rest = 0
if (rest !== parseInt(cpf[9])) return false
sum = 0
for (let i = 1; i <= 10; i++) sum += parseInt(cpf[i - 1]) * (12 - i)
rest = (sum * 10) % 11
if (rest === 10 || rest === 11) rest = 0
return rest === parseInt(cpf[10])
}
|