how do i change the message when a form input doesn’t match the pattern parameter?

The pattern attribute is actually a HTML spec, not a Rails thing. You can use the title attribute to give users a hint on to what format is expected.

<%= f.text_field :username, pattern: "([A-Za-z0-9\-\_]+)",
                            title: "A username can only contain letters, numbers, hyphens and underscores" %>

Find more information here:

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top