Isbister
Isbister

Reputation: 946

HTML5 pattern matching

Is it possible to make some kind of pattern matching with html5 to only allow 3-digit numbers to a text form. I do not want the input type to be number because I dont like the visual design of it.

The closest I get is pattern=".{0.3}" But that accepts all kind of text input - not limited to numbers.

<input type="text" name="price" id="price" pattern="fancy code here">

Question: Can you make a pattern in input type="text" that accepts only integers in the max length of 3?

Upvotes: 2

Views: 281

Answers (1)

Stephan
Stephan

Reputation: 43013

Use this pattern:

\d{1,3}

and the required attribute

Upvotes: 1

Related Questions