Nimmy Nimmy - 1 month ago 6
HTML Question

Input number to show in two digit format in HTML5

How can I make an html input that always has two digits, like 01, 02 , 03 etc. with a max at 24 (with a leading zero for single digit numbers)?

<input id="hourInput" type="number" min="1" max="24" step="1" />

Answer

Unfortunately it is not possible, in pure HTML5, to achieve this. Javascript will be required...

<input id="hourInput" type="number" min="1" max="24" step="1" onchange="if(parseInt(this.value,10)<10)this.value='0'+this.value;" />