Wednesday 18 September 2013

Set Max Length on an HTML TextArea Control

  var limit = 10;

  $(document).ready(function(){

    $('textarea').keypress(function()
    {
      return $(this).val().length < limit;
    });

              $('textarea').keyup(function(){
     
                  var text = $(this).val();
 
                   if(text.length > limit){
     
                    $(this).val(text.substr(0,limit));
                 }  
              })
  });

Actually the best option perhaps would be using this jquery plugin: http://jqueryvalidation.org/