Return to Snippet

Revision: 11759
at February 17, 2009 13:21 by jlvallelonga


Initial Code
function validateLength(event, limit, str) {
	notTooLong = true;
	okKeyCodes = new Array(8, 116, 37, 38, 39, 40);
	if (str.length >= limit && !(isValueInArray(okKeyCodes, event.keyCode))) {
		alert("text area limit reached");
		notTooLong = false;
	}
	return notTooLong;
}

Initial URL


Initial Description
this function returns if the passed string is shorter than the limit or not
when you press keys other than F5, backspace, or any arrow keys and the limit is reached it shows an alert.

use with isValueInArray function

Initial Title
validate length of string

Initial Tags


Initial Language
JavaScript