Word counter

suggest change

Say you have a <textarea> and you want to retrieve info about the number of:

function wordCount( val ){
    var wom = val.match(/\S+/g);
    return {
        charactersNoSpaces : val.replace(/\s+/g, '').length,
        characters         : val.length,
        words              : wom ? wom.length : 0,
        lines              : val.split(/\r*\n/).length
    };
}

// Use like:
wordCount( someMultilineText ).words;   // (Number of words)

jsFiddle example

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents