Ash FrameworkAF
Ash Framework3y ago
3 replies
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
Was this page helpful?