开发者

regex (or any other method) for finding the number of newline charcters in the text the user inputs in a textarea

开发者 https://www.devze.com 2023-03-14 07:36 出处:网络
i need to count the number of newline characters (or whatever is inserted when the user press the return key) in the value of a textarea. I think i should use a regular expression, but i\'m really bad

i need to count the number of newline characters (or whatever is inserted when the user press the return key) in the value of a textarea. I think i should use a regular expression, but i'm really bad ad it and i don't know what i should look for.

<text开发者_如何学Carea id='countIt'></textarea>

var value = $('#countIt').val();

 //need help from here

Of course if there is a smarter method, feel free to suggest


Try value.split(/\n/).length - 1


var breaksArray = value.match(/(\r\n|\n|\r)/);
0

精彩评论

暂无评论...
验证码 换一张
取 消