diff options
Diffstat (limited to 'lib/chessh/schema')
-rw-r--r-- | lib/chessh/schema/player.ex | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/chessh/schema/player.ex b/lib/chessh/schema/player.ex index d5bcab2..19142e9 100644 --- a/lib/chessh/schema/player.ex +++ b/lib/chessh/schema/player.ex @@ -43,6 +43,12 @@ defmodule Chessh.Player do |> validate_discord_id() end + def username_changeset(player, attrs) do + player + |> cast(attrs, [:username]) + |> validate_username() + end + def registration_changeset(player, attrs, opts \\ []) do player |> cast(attrs, [:username, :password, :discord_id]) @@ -85,7 +91,9 @@ defmodule Chessh.Player do changeset |> validate_required([:username]) |> validate_length(:username, min: 2, max: 40) - |> validate_format(:username, ~r/^.{3,32}#[0-9]{4}$/, message: "must match discord tag format") + |> validate_format(:username, ~r/^.{3,32}(#[0-9]{4})?$/, + message: "must match discord tag format" + ) |> unique_constraint(:username) end |