Elixir package that validates a Canadian SIN and can get the SIN's province
The package can be installed by adding canada_sin to your list of dependencies in mix.exs:
def deps do
[
{:canada_sin, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/canada_sin.
Note: The SIN used in example is a fake SIN. It does not belongs to anyone
You can use the CanadaSin.valid?/1 function to validate if the sin matches Canadian rules. You can pass in a string or a number, since first char 0 is not used in Canada.
CanadaSin.valid? "130 692 544"You can also pass in an integer directly
CanadaSin.valid? 130692544You can also get valid provinces. Using the CanadaSin.province/1 will return a list of atom of province codes
Note: It does not validate the SIN, it only gives the province matching the first digit. It would return [] for an invalid province code.
CanadaSin.province ("211 111 111")
[:QC]For references on how the SIN is calculated, you can refer here http://www.straightlineinternational.com/docs/vaildating_canadian_sin.pdf.