is there support for pattern attribute when using form_for?
<%= form_for order_form do |f| %>
<%= f.label "name" %>
<%= f.text_field :name, required: true %>
<%= f.label "Number" %>
<%= f.telephone_field :phone, pattern: "\\d{10}" %>
<%= f.submit %>
I'm trying to put together a regex pattern to ensure that phone numbers are in correct format. My problem is that the pattern attribute wont take regex only strings
<%= f.telephone_field :phone, pattern: /\d{10}/ %> doesnt work
so when i write the regex as a string it causes problems, (like having to escape backslashes e.g.
"\\d{10}" == /\d{10}/
should i just forgo using form_for on this form or is there a way to use form_for and pattern matching together
pattern: "\\d{10}"a problem? Thepatternattribute in HTML holds text that is interpreted as a JavaScript regex (not a Ruby one). If typing\\dis really so much trouble then usepattern: '\d{10}'instead. Embedding one language inside another is always a little messy, more so when you're embedding one language (JavaScript regex) inside another (HTML) inside another (Ruby) inside another (ERB).