javascript - js怎么判断字符串是不是全是空格
本文介绍了javascript - js怎么判断字符串是不是全是空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<input type="text" name="keyWords" autocomplete="off" id="keyWords" >
input框中输入,怎么判断是不是全部输入的都是空格
解决方案
用正则表达式。
var test = " \n ";
//var test = " ";
if(test.match(/^\s+$/)){
console.log("all space or \\n")
}
if(test.match(/^[ ]+$/)){
console.log("all space")
}
if(test.match(/^[ ]*$/)){
console.log("all space or empty")
}
if(test.match(/^\s*$/)){
console.log("all space or \\n or empty")
}
这篇关于javascript - js怎么判断字符串是不是全是空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文