I have this function
String.prototype.countWords = function(){
return this.split(/\s+\b/).length;
}
which counts words in textarea, but it also counts numbers inserted, I was wondering how to count words but not numbers, so ignoring the numbers,
The following regex might help you out:
String.prototype.countWords = function(){
return this.split(/\s+[^0-9]/).length;
}
The ^ negates the characters in the brackets, so all characters are allowed to follow the whitespaces except any numbers.
By the way: here is a good place to test your regex: http://regexpal.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With