View Source ElixirCLRut (ElixirCLRUT v1.0.0)

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

Formats a string or Rut struct with the Rut format.

When given a string it will return an ElixirCLRut.Struct

Performs a simple validation and returns the boolean result. true if is valid.

Executes the rut validations.

Link to this section Functions

Link to this function

format(input, sep \\ ".")

View Source (since 1.0.0)
@spec format(struct() | String.t(), String.t()) :: String.t()

Formats a string or Rut struct with the Rut format.

examples

Examples

iex> format("1")
"1-9"

iex> format(from("6300948-2"), ",")
"6,300,948-2"
Link to this function

from(input)

View Source (since 1.0.0)
@spec from(String.t()) :: struct()

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", lastdigit: "9", normalized: [1], normalized_with_checkdigit: [1, 9]}
Link to this function

valid?(input)

View Source (since 1.0.0)
@spec valid?(struct() | String.t()) :: boolean()

Performs a simple validation and returns the boolean result. true if is valid.

examples

Examples

iex> valid?("1")
true

iex> valid?("6300948-1")
false

iex> valid?(from("6300948-1"))
false
Link to this function

validate(input)

View Source (since 1.0.0)
@spec validate(struct() | String.t()) :: struct()

Executes the rut validations.

examples

Examples

iex> validate("1").valid?
true

iex> validate("6300948-1").valid?
false