jQuery way to limit input characters using javascript substring function

It’s an example of useful jQuery way to limit user entering a maximum set number of character in your input fields. Example makes use of javascript substring function to limit user upto 20 character which is triggered on keyup event. It truncate anything extra to that limit.

		var text = $(this).val();
		if(text.length > 20) {
			text = text.substring(0, 20);

Leave a Reply