码迷,mamicode.com
首页 > Web开发 > 详细

JS判断字符串是否为空或是否全为空格

时间:2017-11-28 01:25:51      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:字符串   mat   console   ace   test   ons   字符   var   pre   

 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判断字符串是否为空或是否全为空格

标签:字符串   mat   console   ace   test   ons   字符   var   pre   

原文地址:http://www.cnblogs.com/chmo/p/7906595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!