View Source ElixirCLRut (ElixirCLRUT v1.0.3)
A module that helps with validation and formatting of chilean RUT/RUN identifiers. Made by the Elixir Chile Community.
Link to this section Summary
Functions
Gets the check digit of a rut
Cleans a RUT
Alternate name for checkdigit/2
Formats a string or Rut struct with the Rut format.
When given a string it will return an ElixirCLRut.Struct
Executes the rut validations.
Performs a simple validation and returns the boolean result. true if is valid.
Link to this section Functions
Gets the check digit of a rut
- since: "1.0.3"
Cleans a RUT
- since: "1.0.2"
Alternate name for checkdigit/2
- since: "1.0.3"
Link to this function
format(input, options \\ [dashed?: true, separator: "."])
View Source (since 1.0.1)Formats a string or Rut struct with the Rut format.
examples
Examples
iex> format("1", false)
"1-9"
iex> format("K", false)
"K"
iex> format("63009482", true)
"6.300.948-2"
iex> format("6300948-2", dashed?: true, separator: ",")
"6,300,948-2"
iex> format("141231553")
"14.123.155-3"
When given a string it will return an ElixirCLRut.Struct
example
Example
iex> from("1-9")
%ElixirCLRut.Struct{checkdigit: "9", dashed?: true, from: "1-9", includes_checkdigit?: true, lastdigit: "9", normalized: [1], normalized_with_checkdigit: [1, 9]}
iex> from("141231553")
%ElixirCLRut.Struct{checkdigit: "3", dashed?: false, from: "141231553", includes_checkdigit?: true, lastdigit: "3", normalized: [1, 4, 1, 2, 3, 1, 5, 5], normalized_with_checkdigit: [1, 4, 1, 2, 3, 1, 5, 5, 3]}
iex> from("14123155", false)
%ElixirCLRut.Struct{checkdigit: "3", dashed?: false, from: "14123155", includes_checkdigit?: false, lastdigit: "3", normalized: [1, 4, 1, 2, 3, 1, 5, 5], normalized_with_checkdigit: [1, 4, 1, 2, 3, 1, 5, 5, 3]}
iex> from("20.961.605-K")
%ElixirCLRut.Struct{checkdigit: "K", dashed?: true, from: "20.961.605-K", includes_checkdigit?: true, lastdigit: "K", normalized: [2, 0, 9, 6, 1, 6, 0, 5], normalized_with_checkdigit: [2, 0, 9, 6, 1, 6, 0, 5, "K"]}
Executes the rut validations.
examples
Examples
iex> valid("1-9").valid?
true
iex> valid("1").valid?
false
iex> valid("6300948-1").valid?
false
Performs a simple validation and returns the boolean result. true if is valid.
examples
Examples
iex> validate("1-9")
true
iex> validate("1k-9")
false
iex> validate("6300948-1")
false
iex> validate(from("6300948-1"))
false