'IsNullOrWhitespace' in JavaScript?

后端 未结 8 1055
-上瘾入骨i
-上瘾入骨i 2020-12-02 22:22

Is there a JavaScript equivalent to .NET\'s String.IsNullOrWhitespace so that I can check if a textbox on the client-side has any visible text in it?

I\'d rather do

8条回答
  •  广开言路
    2020-12-02 22:49

    You can use the regex /\S/ to test if a field is whitespace, and combine that with a null check.

    Ex:

    if(textBoxVal === null || textBoxVal.match(/\S/)){
        // field is invalid (empty or spaces)
    }
    

提交回复
热议问题