JS how to check empty String and Space [duplicate]

两盒软妹~` 提交于 2019-12-23 07:58:06

问题


Help me pls

if(value == ""){
// do anything
}

but I need to check space " " (2,3,... space is include) is the same way of empty String

ps. sorry in my English


回答1:


A regex can easily solve this problem.

if (/^ *$/.test(value)) {
    //string contains 0+ spaces only
}



回答2:


I'm not sure I'm understanding correctly. Do you mean like:

if (value == "" || value == " "){
// do anything
}


来源:https://stackoverflow.com/questions/36490984/js-how-to-check-empty-string-and-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!