skip to Main Content
Javascript Validation To Allow The Only Numeric Value In The Text Field.

Javascript validation to allow the only numeric value in the text field.

How to set the validation to allow only numeric value in the HTML text field using JAVASCRIPT. We can set the validation using window keycode event on JAVASCRIPT. Like we want to allow the user only able to enter the numeric value in the text field just we need to set JAVASCRIPT function called on KeyPress like below.

Let’s create the textbox for set validation.

<input type="text" name="text" onkeypress="return thecodingstuffNumberValue(event)">

Now let’s create the validation function for allowing user to enter the only numeric value.

        function thecodingstuffNumberValue(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode  57)) {
                return false;
            return true;

It’s too easy to set the numeric validation for textbox field using javascript.


I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top