'IsNullOrWhitespace' in JavaScript?

后端 未结 8 1048
-上瘾入骨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:33

    no, but you could write one

    function isNullOrWhitespace( str )
    {
      // Does the string not contain at least 1 non-whitespace character?
      return !/\S/.test( str );
    }
    

提交回复
热议问题