In this post, we will learn, how to make any textbox in HTML to take the only number or numeric value. This value can be either decimal or float.
It is very easy to create such a textbox using HTML5.
Use the input tag and set type property number
<input type="number" />
So this will not take any value other than numeric, remember that it will take only decimal value, not floating type of number.If you will input float data like 2.3, it will again be denied like this-
To take float value you will be required to use step property like this:-
<input type="number" step="0.01" />
Above will take 2 numbers after the decimal and like so on you can define the number to accept.
If you don't want any restriction than use 'any', like this:-
<input type="number" step="any" />
No comments:
Post a Comment