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

This is my current code for the input field. How can I make it display a message stating that the entered number should not start from scratch? thanks

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

For example, you cannot dial 020. Only numbers from 10 to 1000.

+5
source share
2 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/

+3
source

try using the html pattern attribute

<input type="number" class="form-control" name="payment" 
placeholder="enter payment" style="text-align:center" pattern="[1-9]\d*" autofocus required/>
<br/>
0
source

Source: https://habr.com/ru/post/1676888/


All Articles