cnpj/alphanumeric

Values

pub fn calculate_first_verification_digit_alphanumeric(
  first_twelve_chars: List(String),
) -> Result(Int, Nil)

Calculates the first verification digit for an alphanumeric CNPJ.

Uses the modulo 11 algorithm with weights [5,4,3,2,9,8,7,6,5,4,3,2] and ASCII values minus 48 for each character.

pub fn calculate_second_verification_digit_alphanumeric(
  thirteen_chars: List(String),
) -> Result(Int, Nil)

Calculates the second verification digit for an alphanumeric CNPJ.

Uses the modulo 11 algorithm with weights [6,5,4,3,2,9,8,7,6,5,4,3,2] and ASCII values minus 48 for each character.

pub fn clean_alphanumeric(cnpj: String) -> String

Cleans an alphanumeric CNPJ by removing formatting characters but keeping letters and numbers.

This function removes all non-alphanumeric characters except letters (A-Z) and digits (0-9).

pub fn format_alphanumeric(cnpj: String) -> String

Formats an alphanumeric CNPJ string into the standard format: AA.AAA.AAA/AAAA-DV

Example: “12ABC34501DE35” -> “12.ABC.345/01DE-35”

pub fn is_alphanumeric(cnpj: String) -> Bool

Detects if a CNPJ is alphanumeric (contains letters) or purely numeric.

Returns True if the CNPJ contains at least one letter in the first 12 positions.

pub fn validate_alphanumeric(cnpj: String) -> Bool

Validates an alphanumeric CNPJ using the modulo 11 algorithm.

The CNPJ must be exactly 14 characters long, with the first 12 positions containing letters (A-Z) and/or digits (0-9), and the last 2 positions containing only numeric verification digits.

Search Document