2014-10-20 29 views

回答

1

您可以使用正则表达式:

if (str.replace(/[\s\n\r]+/g, "") != "") 
{ 
    // if you remove spaces and line breaks, it doesn't equal nothing 
} 

编辑 - 它应该是更快

if (/\S/.test(str)) 
{ 
    // found something other than spaces or line breaks 

    // "\S" should match any character that is not a space or line break 
} 
+0

感谢猪头,是缺少的东西雷 – Jim 2014-10-20 16:55:39

0

空间只是一堆空格。所以,你可以用下面的方法来检查:

if(s.indexOf(' ') >= 0) return true; 

您可能还需要修整的,而不是检查空格的潜力存在你输入:

s.trim(); 
0

您可以使用修剪和检查的长度。

// it is a bunch of spaces 
if(inputValue.trim().length == 0){ /* ... */} 
相关问题