Password v1.1.1 Password.Policy.SpecialCharacters View Source

Checks whether input contains special characters.

By default, it uses a built-in list of characters (see module’s source), but you can provide your own:

use Password, [
  {Password.Policy.SpecialCharacters, chars: ~w(! @ #)}
]
iex> MyApp.Password.validate("password$")
{:error, [Password.Policy.SpecialCharacters]}

iex> MyApp.Password.validate("password#")
:ok

By default, at least 1 character from the list is required. To change this, use the min option:

use Password, [
  {Password.Policy.SpecialCharacters, min: 2, chars: ~w(! @ #)}
]
iex> MyApp.Password.validate("password!")
{:error, [Password.Policy.SpecialCharacters]}

iex> MyApp.Password.validate("password!@")
:ok