I need to filter a field composed of only spaces; something like:
if (word == /((\s)+)/ ) return 'no name'
but it doesn't work ... any other ideas? thank you for your ideas!
You should use if(/^\s+$/.test(word)). (Notice the ^ and $, without them the regex will hold for any string that has at least a space-like character)
How about NOT checking "word" by RegExp but using RegExp to replace all whitespaces and look what's left. If it's empty "word" is only composed by whitespaces:
if (word.replace(/\s+/, "") === "") {
console && console.log("empty string found!");
return 'no name';
}
console & ... makes no sense and the parens around word are redundant.