Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  119] [ 3]  / answers: 1 / hits: 38070  / 13 Years ago, tue, september 20, 2011, 12:00:00

I have to get the value from a textarea using jQuery and count the number of newlines there. I'd like to do this using a regex-expression. Does anyone know how to do that?


More From » jquery

 Answers
46

regex does not have count. better use array like this



var val = textarea.value;
var arr = val.split(/[nr]/g);
var count = arr.length;


you could condense this in less rows and vars...



var count = $('textarea').val().split(/[nr]/g).length;

[#90015] Saturday, September 17, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katianatasham

Total Points: 293
Total Questions: 110
Total Answers: 103

Location: Saint Helena
Member since Mon, Jun 28, 2021
3 Years ago
;