diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index 05d6a01c..cfd40b27 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -161,7 +161,7 @@ defmodule Philomena.Users.User do defp validate_email(changeset) do changeset |> validate_required([:email]) - |> validate_format(:email, ~r/^[^\s]+@[^\s]+$/, message: "must have the @ sign and no spaces") + |> validate_format(:email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/, message: "must be valid (e.g., user@example.com)") |> validate_length(:email, max: 160) |> unsafe_validate_unique(:email, Philomena.Repo) end diff --git a/lib/philomena_web/templates/registration/edit.html.slime b/lib/philomena_web/templates/registration/edit.html.slime index 977110d0..7e40e174 100644 --- a/lib/philomena_web/templates/registration/edit.html.slime +++ b/lib/philomena_web/templates/registration/edit.html.slime @@ -35,7 +35,7 @@ h3 Change email p Oops, something went wrong! Please check the errors below. .field - = email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ".*@.*" + = email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/ = error_tag f, :email .field diff --git a/lib/philomena_web/templates/registration/new.html.slime b/lib/philomena_web/templates/registration/new.html.slime index eb789ae2..fb19a3fc 100644 --- a/lib/philomena_web/templates/registration/new.html.slime +++ b/lib/philomena_web/templates/registration/new.html.slime @@ -16,7 +16,7 @@ h1 Register ' You'll use your email address to log in, and we'll use this to get in ' touch if we need to. Don't worry, we won't share this or spam you. .field - = email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ".*@.*" + = email_input f, :email, class: "input", placeholder: "Email", required: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/ = error_tag f, :email .fieldlabel diff --git a/lib/philomena_web/templates/session/new.html.slime b/lib/philomena_web/templates/session/new.html.slime index 4c418d78..112ebaae 100644 --- a/lib/philomena_web/templates/session/new.html.slime +++ b/lib/philomena_web/templates/session/new.html.slime @@ -10,7 +10,7 @@ h1 Sign in p = link "Forgot your password?", to: Routes.password_path(@conn, :new) .field - = email_input f, :email, class: "input", required: true, placeholder: "Email", autofocus: true, pattern: ".*@.*" + = email_input f, :email, class: "input", required: true, placeholder: "Email", autofocus: true, pattern: ~S/[^\s]+@[^\s]+\.[^\s]+/ = error_tag f, :email .field diff --git a/test/philomena/users_test.exs b/test/philomena/users_test.exs index a641f8e2..c66c5da1 100644 --- a/test/philomena/users_test.exs +++ b/test/philomena/users_test.exs @@ -97,7 +97,7 @@ defmodule Philomena.UsersTest do {:error, changeset} = Users.register_user(%{email: "not valid", password: "not valid"}) assert %{ - email: ["must have the @ sign and no spaces"], + email: ["must be valid (e.g., user@example.com)"], password: ["should be at least 12 character(s)"] } = errors_on(changeset) end @@ -167,7 +167,7 @@ defmodule Philomena.UsersTest do {:error, changeset} = Users.apply_user_email(user, valid_user_password(), %{email: "not valid"}) - assert %{email: ["must have the @ sign and no spaces"]} = errors_on(changeset) + assert %{email: ["must be valid (e.g., user@example.com)"]} = errors_on(changeset) end test "validates maximum value for email for security", %{user: user} do diff --git a/test/philomena_web/controllers/registration_controller_test.exs b/test/philomena_web/controllers/registration_controller_test.exs index 98a5811f..c904a129 100644 --- a/test/philomena_web/controllers/registration_controller_test.exs +++ b/test/philomena_web/controllers/registration_controller_test.exs @@ -41,7 +41,7 @@ defmodule PhilomenaWeb.RegistrationControllerTest do }) response = html_response(conn, 200) - assert response =~ "must have the @ sign and no spaces" + assert response =~ "must be valid (e.g., user@example.com)" assert response =~ "should be at least 12 character" end end