Bhardwaz Chetry
Bhardwaz Chetry

Reputation: 31

HTML input pattern that includes only specific numbers

I want the value 100, 200, 300, 400, 500 only to be valid in my input. I don't even want value 101. So how should I write the pattern.

Upvotes: 1

Views: 209

Answers (2)

jeetendra Mandal
jeetendra Mandal

Reputation: 150

The easiest and safe way is to use Drop-down field with HTML Tag "select" and add "OPTION" values as 100, 200.

<option value="100">100</option> <option value="200">200</option>

this will minimize the typo error validation message to user.

Upvotes: 0

Itay Gal
Itay Gal

Reputation: 10834

Add this to your element:

pattern="[1-5][0][0]"

for example:

<form>
  <input type="text" pattern="[1-5][0][0]">
  <input type="submit">
</form>

Upvotes: 1

Related Questions