Reputation: 19
My question is about validation in html. At the moment, if I input 100 or 1000 it will work as intended.
This is my html code:
<tr>
<th scope="row" colspan = "1"><font size="5">Number of Guests:</th>
<td colspan = "2"><input type = "text" name = "guest" maxlength = "4" id="guest"
pattern="[0-9]{3,4}" title = "Number of guests must be more than 100 people."></td>
</tr>
My problem is that when I try to input 001 or 000 it still works. How can I counter that problem? Do I have to validate in php? Thank you for any comments or suggestions.
Upvotes: 1
Views: 95
Reputation: 11808
Use following code to get you desired value only.
<input type = "text" name = "guest" maxlength = "4" id="guest" min="100" max="1000" pattern="^[1-9][0-9]*$" title = "Number of guests must be more than 100 people.">
Upvotes: 0
Reputation: 2115
Try this pattern:
^(0?[1-9][0-9]{2}|[1-9][0-9]{3})$
this way you disallow input 0100,001,099,0099
Upvotes: 0
Reputation: 368
Try This it will work for numbers
<input type = "number" name = "guest" min = "100" max="1000" id="guest" title = "Number of guests must be more than 100 people.">
Upvotes: 3