validateCpf function is a utility for validating Brazilian CPF (Cadastro de Pessoas Físicas) numbers. The CPF is a unique identifier assigned to Brazilian citizens and residents. This function performs comprehensive validation including format checking, length verification, and mathematical validation of the two check digits using the official algorithm.ts
import { validateCpf } from "@arkyn/server";
rawCpf (required)XXX.XXX.XXX-XX) and the raw numeric format (XXXXXXXXXXX).stringbooleantypescript
import { validateCpf } from "@arkyn/server";// Valid formatted CPFconst isValid1 = validateCpf("111.444.777-35");console.log(isValid1);// Output: true// Valid unformatted CPFconst isValid2 = validateCpf("11144477735");console.log(isValid2);// Output: true// Invalid CPF (wrong check digits)const isValid3 = validateCpf("123.456.789-09");console.log(isValid3);// Output: false// Invalid CPF (all digits equal)const isValid4 = validateCpf("111.111.111-11");console.log(isValid4);// Output: false
false if the input is empty or null.false if the raw input length is greater than 14 characters or less than 11 characters.false if the input contains any whitespace characters.false if all 11 digits are identical (e.g., 11111111111), as these are mathematically valid but not issued.removeNonNumeric from @arkyn/shared internally to strip formatting characters before validation.