AE
Ash Elixir•2y ago
Jason

attribute match constraints error message

When validating email format using regex, is there an easier way to show a more user friendly validation error message such as "invalid email format" rather than the default "must match the pattern ~r/[a-z...."? I believe it can be done inside action definition, but thought I might be missing an easier way to do the same in the attribute definition.
attribute :email, :ci_string do
allow_nil? false
constraints match: ~r/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/
end
attribute :email, :ci_string do
allow_nil? false
constraints match: ~r/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/
end
3 Replies
frankdugan3
frankdugan3•2y ago
We had a discussion about that here: https://discord.com/channels/711271361523351632/712035333432147989/1088140734634401935 TLDR: PR welcome, I was going to do it and then got distracted. 😅
Jason
JasonOP•2y ago
I see. Thanks!
ZachDaniel
ZachDaniel•2y ago
In the meantime, you can use the match validation instead of the constraint

Did you find this page helpful?