A pattern argument can be provided to a form field as described here
Example (regex from here)
<%= f.text_field :username, pattern: "([A-Za-z0-9\-\_]+)" %>
When the regex is not adhered to, a message is displayed. E.g.:
How can that message be customised?

The
patternattribute is actually a HTML spec, not a Rails thing. You can use thetitleattribute to give users a hint on to what format is expected.Find more information here: https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute