JP P.
JP P.

Reputation: 183

How to use HTML5 pattern attribute in Pug (Jade) template

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

Answers (1)

JP P.
JP P.

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

Related Questions