Issue
I have got an input field called Fleet no.
I want to validate it using HTML 5 to only allow the input of digits to 5 digit max length.
I have managed to only input digits but it only accepts 1 digit.
I can't put more than 1 digit. 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>
Solution
Use [0-9]{1,5}
<input type="text" pattern="[0-9]{1,5}" />
{1,5}
means repeat the previous part 1, 2, 3, ..., 5 times.
Answered By - Wouter J
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.