Reputation: 1528
I used input pattern in input type="text"
its working
its working code
<input name="name" required pattern=".{4,}" title="Please Enter Correct Name" type="text" />
But when I used input pattern in input type="number"
its not working
<input name="number" required type="number" pattern=".{9,20}" title="Please Enter Your Number at least 9 Digit" />
Upvotes: 2
Views: 10357
Reputation: 764
The pattern attributes only works with text
, date
, search
, url
, tel
, email
, and password
input types: HTML5 input specification. Scroll down a bit and you will see a table telling you which attributes can be used with the different input types.
You should use javascript to achieve what you want to do.
Upvotes: 4
Reputation: 593
The pattern attribute works with the following input types: text, date, search, url, tel, email, and password. Therefore you can't use it with input number You can check here
Upvotes: 1
Reputation: 3541
From MDN
A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url, email, or password, otherwise it is ignored.
Upvotes: 6