简体   繁体   中英

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.

<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)/);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM