Skip to content

Instantly share code, notes, and snippets.

@EdCharbeneau
Created March 14, 2014 17:11
Show Gist options
  • Save EdCharbeneau/9552248 to your computer and use it in GitHub Desktop.
Save EdCharbeneau/9552248 to your computer and use it in GitHub Desktop.
Javascript test a string to see if it is Null or Whitespace. Equivelent to C# String.IsNullOrWhiteSpace
function isNullOrWhiteSpace(str) {
return (!str || str.length === 0 || /^\s*$/.test(str))
}
@zoldello
Copy link

I think a better name for this is: "isFalseyOrWhiteSpace"

@DorkForce
Copy link

Thread resurrection here, but in case anyone stumbles upon this, I believe the answer Jeremygithub was looking for was:

String.prototype.isNullOrWhiteSpace = function() { return (!this || this.length === 0 || /^\s*$/.test(this)) }

@Yogiaccount
Copy link

if i have

@Html.EditorFor(m=>m. name) @Html.EditorFor(m=>m. lastname) how i defind that name is empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment