Validation for the Brazilian CNH (Carteira Nacional de Habilitação) registration number, 2022 layout.
A CNH registration number has 11 digits: a 9-digit base followed by 2 check digits. Only the layout introduced in 2022 is supported; earlier CNH layouts are out of scope.
Unlike the CPF/CNPJ/PIS validators in this library,is_valid/1
strips every non-digit character before validating, so formatted
input such as <<"987654321-00">> is accepted.
| is_valid/1 | Returns whether the given term is a valid CNH after stripping every non-digit character: exactly 11 digits remain, they are not a sequence of one repeated digit, and both check digits (the last two) match the ones computed from the 9-digit base. |
is_valid(Cnh::term()) -> boolean()
Returns whether the given term is a valid CNH after stripping every non-digit character: exactly 11 digits remain, they are not a sequence of one repeated digit, and both check digits (the last two) match the ones computed from the 9-digit base.
Letters and symbols are removed, not rejected — an input like
<<"A2C45678901">> fails because only 9 digits remain, not
because it contains letters. Only the format is verified — the CNH
is not checked for existence. The function is total: any
non-binary term returns false rather than raising.
1> brutils_cnh:is_valid(<<"98765432100">>). true 2> brutils_cnh:is_valid(<<"987654321-00">>). true 3> brutils_cnh:is_valid(<<"12345678901">>). false
Generated by EDoc