JS判断字符串是否为空或是否全为空格
Posted 网后鱼生
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS判断字符串是否为空或是否全为空格相关的知识,希望对你有一定的参考价值。
1 var test = " \n "; 2 //var test = " "; 3 if(test.match(/^\s+$/)){ 4 console.log("all space or \\n") 5 } 6 if(test.match(/^[ ]+$/)){ 7 console.log("all space") 8 } 9 if(test.match(/^[ ]*$/)){ 10 console.log("all space or empty") 11 } 12 if(test.match(/^\s*$/)){ 13 console.log("all space or \\n or empty") 14 }
以上是关于JS判断字符串是否为空或是否全为空格的主要内容,如果未能解决你的问题,请参考以下文章