Packages
eview
0.10.3
0.16.0
retired
0.15.0
0.14.0
0.13.0
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.1
0.11.0
0.10.8
0.10.7
0.10.6
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.9
0.2.7
0.2.6
0.2.5
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Plug that converts response to Nebo #15 API spec format.
Current section
Files
Jump to
Current section
Files
lib/eview/changeset/validators/email_validator.ex
if Code.ensure_loaded?(Ecto) do
defmodule EView.Changeset.Validators.Email do
@moduledoc """
This helper validates emails by complex regex pattern.
"""
import Ecto.Changeset
@email_regex Regex.compile!(~S((?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+\)*|") <>
~S((?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f]\)*"\)) <>
~S(@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9]\)?\.\)+[a-z0-9](?:[a-z0-9-]*[a-z0-9]\)?) <>
~S(|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\)\.\){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) <>
~S(|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]) <>
~S(|\\[\x01-\x09\x0b\x0c\x0e-\x7f]\)+\)\]\)))
def validate_email(changeset, field, opts \\ []) do
validate_change changeset, field, {:email, @email_regex}, fn _, value ->
if value =~ @email_regex, do: [], else: [{field, {message(opts, "is not a valid email"), [validation: :email]}}]
end
end
defp message(opts, key \\ :message, default) do
Keyword.get(opts, key, default)
end
end
end