Reputation: 183
With Pug (previously named Jade) templating engine, how can I use the pattern attribute of an input ?
When I use a pattern like:
input( type="tel", pattern="\d{7}" )
the rendered pattern is:
<input type="tel" pattern="d{7}">
I also tried with the unescaped attribute != but it still escapes the \
character.
Note: it works perfectly with pattern="[0-9]{7}"
.
Upvotes: 5
Views: 3164
Reputation: 183
The problem here is that the \
character is used to escape Javascripts's own special characters.
You need to escape it so it will be rendered in the pattern, as explained here.
input( type="tel", pattern="\\d{7}" )
will render properly as:
<input type="tel" pattern="\d{7}">
Upvotes: 8