Validate Input using Javascript

JavaScript has  been the most accepted language to provide on page validation for all web scripting languages.

Developers working on web applications are keen to provide client side validation on their websites.

I have some of the useful functions that can save your time and Postback for ASP.NET guy :)


Validating the total number of characters allowed in the text box:

Place the following function just above your /Head tag (trying to provide more useful statements for novice )


<script type="text/javascript">

function limitchars(txtinput, maxlimit) {
if (txtinput.value.length > maxlimit) {
alert("Oops! You exceeded the limit. Max avalibale length is " + maxlimit + " characters\n You entered " + txtinput.value.length + " characters.");
reftxtreftxt.value = txtinput.value.substring(0, maxlimit);
}
}

</script>

Place the following HTML code after your /Body tag

<textarea name="txt" rows="7" cols="20" onblur="limitchars(this,25)"></textarea>


This will limit the user to enter maximum 25 characters in the textbox.


By
Image credit: http://aztips.in

No comments:

Post a Comment