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

Question
 
How to check/validate a textbox has numeric value or not in asp.net using javascript? Also, validate when the textbox is null.
 
Answer
 
Suppose, we have a textbox on the form and its ID='txtAge'. and we also have a button control and it's ID='btn1' Now this is the javascript code :
  1.  <script type="text/javascript">       
  2.      function validate() {  
  3.         var age = document.getElementById('<%=txtAge.ClientID %>').value;   
  4.         if age== "") {  
  5.             alert('enter age');  
  6.             return false;  
  7.         }  
  8.         else {  
  9.             if (isNaN(age)) {  
  10.                 alert('enter a valid age');  
  11.                 return false;  
  12.             }  
  13.        }  
  14. }  
  15.   
  16. </script> 
     
Now you have to set the Button(btn1) onclientclick property.
 
For example
 
onclientclick="return validate();"
 

Conclusion

 
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.