Advertisement
rAthus

[jQuery] limiter nombre caractères dans textarea

Jan 15th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('textarea').on('keypress change blur',function(e)
  2. {
  3.     var tval = $('textarea').val(),
  4.         tlength = tval.length,
  5.         set = 250, // max chars number
  6.         remain = parseInt(set-tlength);
  7.     $('.remain').text(remain);
  8.     if (remain<=0 && e.which!==0 && e.charCode!==0)
  9.         $('textarea').val((tval).substring(0,tlength-1))
  10. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement