Textarea | val().length not counting "Enter/Line Breaks" in chrome Textarea | val().length not counting "Enter/Line Breaks" in chrome google-chrome google-chrome

Textarea | val().length not counting "Enter/Line Breaks" in chrome


$("textarea").keyup(function (e) {var isChrome = window.chrome;if(isChrome){var value = $(this).val().replace(/(\r\n|\n|\r)/g,"  ");}else{var value = $(this).val();}        if(value.length >=350){            $('.error').show();        }else{            $('.error').hide();        }    });

Chrome counts line break as 2 character, so it counts the characters wrong. Just add this code in front of the function and it will work just fine.

https://jsfiddle.net/3wpqd4nr/

Fiddle