Tags

, , , ,

Always use input event for validation so as whenever key press or up but does not change the text change the content in textarea like cltr / Alt / up / down keys , mouse roller paste in linux ,  that time events like keyup , press will not work

so use input change event every time for input field validation.

also make sure server side validation working

<textarea class=”col-md-12 form-control” rows=”5″ id=”msg” name=”msg”></textarea>

var allowedCount=110;
var textCount=$(“#msg”).val().length;;
$(“#infomsg”).empty().text(allowedCount);

$(“#msg”).on(‘keyup change input’,function(){
textCount = $(“#msg”).val().length;
if(textCount <= allowedCount){
$(“#infomsg”).empty().text((allowedCount-textCount));
}else if(textCount > allowedCount){
$(“#msg”).val($(“#msg”).val().substr(0, allowedCount));
$(“#infomsg”).empty().text($(“#msg”).val().length);
}else{
return false;
}
});

Advertisements