Aarthna Maheshwari Aarthna Maheshwari - 1 month ago 12
HTML Question

Restricting inputs in html form elements

I have a form which contains a textbox. i want the textbox to accept only three numbers i.e. 1, 3 or 6. How can i apply such a validation at the client side.

<input type="number" name="NumberOfDays" min="1" />

Answer Source

Using RegEx pattern, you can validate the input. The input will not accept anything other than 1 or 3 or 6. Try adding some value and submitting it. And remove the type="number", if you are using pattern.

<form>
  <input pattern="[1|3|6]{1}" name="NumberOfDays" min="1" />
  <input type="submit" />
</form>