Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the input type="number" to not accept number with leading zeros?

Tags:

html

This is my current code for the input field. How can I make it display a message saying that the number I've entered should not start with zero? thanks

<input type="number" min="10" max="1000" class="form-control" name="payment" 
placeholder="enter payment" style="text-align:center" autofocus required/>
<br/>

For instance, typing 020 should not be accepted. Only numbers between 10 to 1000.

like image 736
Clark Bernales Avatar asked Oct 17 '22 12:10

Clark Bernales


1 Answers

This should work:

<input type="text" class="form-control" name="payment" 
 placeholder="enter payment" style="text-align:center" autofocus required 
 pattern="[1-9]\d*" title="A number with no starting zeros"/>

https://jsfiddle.net/spL2par2/

like image 159
MaanooAk Avatar answered Nov 15 '22 10:11

MaanooAk