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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM