[英]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. 我需要在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.
我想我应该使用正则表达式,但我真的很糟糕,并且我不知道我应该寻找什么。
<textarea id='countIt'></textarea>
var value = $('#countIt').val();
//need help from here
Of course if there is a smarter method, feel free to suggest 当然,如果有更聪明的方法,请随时提出建议
尝试value.split(/\\n/).length - 1
var breaksArray = value.match(/(\r\n|\n|\r)/);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.