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 :
- <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;
- }
- }
- }
- </script>
Now you have to set the Button(btn1) onclientclick property.

SubashPosted Sep 7, 2016, 2:45 AM
Good