In the <Head> tag of the
design page (.aspx) create the JavaScript function to validate the number range
of values e.g. we are validating the age to be between 18 – 25. I have created
the validation function using AND (&&) logical operator and using
nested if (or we can say else-if ladder) .You can use any one of the two validateAge() functions.

Using AND (&&) Operator

<scripttype="text/javascript">

function validateAge() {

var txtVal = document.getElementById("<%=txtAge.ClientID%>").value;

if (txtVal >= 18 && txtVal
<= 25) {

returntrue;

}

else

alert('Age
must be between 18-25');

returnfalse;

}

</script>

<noscript><h3style="color: #FF3300;">

Javascript is not currently enabled
in your browser.<br/> You must <ahref="http://support.google.com/bin/answer.py?hl=en&answer=23852"target="_blank">enable
Javascript </a> to run this web page correctly.

</h3></noscript>

Using else-if ladder

<scripttype="text/javascript">

function validateAge()

{

var txtVal = document.getElementById("<%=txtAge.ClientID%>").value;

if (txtVal < 18)

{

alert('Age
must be greater than 18');

returnfalse;

}

elseif (txtVal > 25)

{

alert('Age
must be lesser than 25');

returnfalse;

}

else

returntrue;

}

</script>

<noscript><h3style="color: #FF3300;">

Javascript is not currently enabled
in your browser.<br/> You must <ahref="http://support.google.com/bin/answer.py?hl=en&answer=23852"target="_blank">enable
Javascript </a> to run this web page correctly.

</h3></noscript>

In the <Body> tag of the
design page (.aspx) place a TextBox control and a Button control on the page. We
will call the function to validate the number range created on the Button’s
OnclientClick event.

Now run the web application and enter number/value greater than 25 or less than 18, it will show the error alert/ message as shown below otherwise the valid entered value will be shown in alert box/message box

Now over to you:

"If you like my work; you can appreciate by leaving your comments,
hitting Facebook like button, following on Google+, Twitter, Linked in and
Pinterest, stumbling my posts on stumble upon and subscribing for receiving
free updates directly to your inbox . Stay tuned and stay connected for more
technical updates."

Related Post

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..
ConversionConversionEmoticonEmoticon