Posted By

jlvallelonga on 02/17/09


Tagged

character String count length validate textarea


Versions (?)

validate length of string


 / Published in: JavaScript
 

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

  1. function validateLength(event, limit, str) {
  2. notTooLong = true;
  3. okKeyCodes = new Array(8, 116, 37, 38, 39, 40);
  4. if (str.length >= limit && !(isValueInArray(okKeyCodes, event.keyCode))) {
  5. alert("text area limit reached");
  6. notTooLong = false;
  7. }
  8. return notTooLong;
  9. }

Report this snippet  

You need to login to post a comment.