开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜