.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

TextBox MaxLength Validation and Display Remaining Characters

Posted By:Lakhan Pal Garg       Posted Date: October 05, 2009    Points: 10    Category: Javascript    URL: http://www.dotnetspark.com  

Text Box OR Text area max length validation and also display the words remaining.
(1) TextBox or Text Area ID
(2) Label ID where we want to show count of remaining character.
(3) Number of Maximum character that are allowed.

Sample Code:
function CountCharactersGeneral(sourceTextBox, displayControl, maxLength)
if(sourceTextBox != null && displayControl != null)
sourceTextBox = document.getElementById(sourceTextBox);
displayControl = document.getElementById(displayControl);
if(sourceTextBox != null)
var len = sourceTextBox.value.length
if (len<=maxLength)
displayControl.innerHTML = maxLength -len +" Character(s) remaining.";
sourceTextBox.value = sourceTextBox.value.substring(0, maxLength);
return false;

Thanks & Regards
Lakhan pal Garg


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend