validateCep function is a utility for validating Brazilian CEP (Código de Endereçamento Postal) values. It checks whether a given string represents a valid postal code format, accepting both formatted (12345-678) and unformatted (12345678) inputs.ts
import { validateCep } from "@arkyn/server";
rawCep (required)XXXXX-XXX) and the raw numeric format (XXXXXXXX).stringbooleantypescript
import { validateCep } from "@arkyn/server";// Formatted CEPconst isValid1 = validateCep("12345-678");console.log(isValid1);// Output: true// Unformatted CEPconst isValid2 = validateCep("12345678");console.log(isValid2);// Output: true// Invalid CEP (contains letters)const isValid3 = validateCep("ABCDE-123");console.log(isValid3);// Output: false// Invalid CEP (wrong length)const isValid4 = validateCep("1234-567");console.log(isValid4);// Output: false
XXXXX-XXX (5 digits, hyphen, 3 digits)XXXXXXXX (8 consecutive digits)removeNonNumeric from @arkyn/shared internally to strip non-numeric characters before performing the final length validation.