How to Check a TextBox has Numeric Value or not in ASP.NET using JavaScript

How to check/validate a textbox has numeric value or not in using javascript ? 
Also validate when textbox is null.

 Answer Suppose, we have a textbox on the form and it's ID='txtAge'. and we also have a button control
and it's ID='btn1' Now this is the javascript code :

<script type="text/javascript">     
     function validate() {
        var age = document.getElementById('<%=txtAge.ClientID %>').value; 
        if age== "") {
            alert('enter age');
            return false;
        else {
            if (isNaN(age)) {
                alert('enter a valid age');
                return false;


Now you have to set the Button(btn1) onclientclick property.

For example

onclientclick="return validate();"


Using this we can check that a textbox has value or not. If it is not then it shows alert to enter text. And, if the textbox has value then we check that the entered value is numeric or not.

Ebook Download
View all
View all