HTML 5 - regular expression of a number

I have an input field called Fleet no.

I want to test it with HTML 5 to allow the input of numbers up to a 5-digit maximum length.

I managed to enter only numbers, but it accepts only 1 digit.

I can not put more than 1 digits. This is what I tried to do:

<div> <label for="element_1">Fleet Number </label> <input id="element_1" name="element_1" type="text" maxlength="255" value="" required placeholder="Enter Digits only" pattern = "[0-9]" title='Fleet No. must contain digits only'/> </div> 
+7
source share
2 answers

Use [0-9]{1,5}

{1,5} means repeating the previous part 1, 2, 3, ..., 5 times.

+10
source

This is the most understandable way.

 <input type="text" pattern="\d{1,5}" title="Only digits" /> 
+11
source

All Articles