'IsNullOrWhitespace' in JavaScript?

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

    trim() is a useful string-function that JS is missing..

    Add it:

    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"") }
    

    Then: if (document.form.field.value.trim() == "")

提交回复
热议问题