Sunday, 1 November 2020

Textbox to input only number/numeric value in HTML5.

 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

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...