Functions for formatting and validating CPF values.
Summary
Types
A formatted CPF follows the XXX.XXX.XXX-XX mask.
A normalized CPF has 11 digits and no punctuation.
Functions
Calculates the two numeric check digits for a 9-digit CPF base.
Formats a CPF using the XXX.XXX.XXX-XX mask.
Formats a CPF, raising ArgumentError when the input is invalid.
Removes punctuation from a CPF.
Removes punctuation from a CPF, raising on invalid input.
Returns true when the CPF format and check digits are valid.
Returns true when the CPF has a supported shape.
Types
Functions
Calculates the two numeric check digits for a 9-digit CPF base.
Examples
iex> BrDocs.CPF.check_digits("123456789")
"09"
Formats a CPF using the XXX.XXX.XXX-XX mask.
The input may be provided with or without punctuation.
Examples
iex> BrDocs.CPF.format("12345678909")
{:ok, "123.456.789-09"}
iex> BrDocs.CPF.format("123")
{:error, :invalid_format}
Formats a CPF, raising ArgumentError when the input is invalid.
Examples
iex> BrDocs.CPF.format!("12345678909")
"123.456.789-09"
@spec unformat(String.t()) :: {:ok, normalized()} | {:error, :invalid_format}
Removes punctuation from a CPF.
Examples
iex> BrDocs.CPF.unformat("123.456.789-09")
{:ok, "12345678909"}
@spec unformat!(String.t()) :: normalized()
Removes punctuation from a CPF, raising on invalid input.
Examples
iex> BrDocs.CPF.unformat!("123.456.789-09")
"12345678909"
Returns true when the CPF format and check digits are valid.
Examples
iex> BrDocs.CPF.valid?("123.456.789-09")
true
iex> BrDocs.CPF.valid?("123.456.789-00")
false
iex> BrDocs.CPF.valid?("111.111.111-11")
false
Returns true when the CPF has a supported shape.
This checks length and allowed characters, but does not calculate check
digits. Use valid?/1 for full validation.
Examples
iex> BrDocs.CPF.valid_format?("123.456.789-09")
true
iex> BrDocs.CPF.valid_format?("1234567890A")
false