I’m trying to write a function that return the value of non-whitespace characters that are inside a textarea. I’m supposed to use replace and the regex given to me to separate whitespace and actual characters but I just don’t understand how I’m supposed to get the count. Could someone explain it to me please?
function countText()
{
var commentText;
var commentBox = document.getElementById('comment'); //comment is my textArea ID
var commentregx = "/\s/g"; // whitespace regex
commentText = commentBox.value.replace(commentregx, ""); // commentText is supposed to hold the number of non-whitespace values.
}
If needed I can throw this into a jsfiddle with my other functions.
The
replaceis returning your string without whitespace, so just grab its length: