Created
December 29, 2010 06:38
-
-
Save laktek/758269 to your computer and use it in GitHub Desktop.
Checks whether the given string (or object) is blank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$.isBlank = function(string){ | |
return(!string || $.trim(string) === ""); | |
}; | |
})(jQuery); | |
$.isBlank(" ") //true | |
$.isBlank("") //true | |
$.isBlank("\n") //true | |
$.isBlank("a") //false | |
$.isBlank(null) //true | |
$.isBlank(undefined) //true | |
$.isBlank([]) //true | |
yckart
commented
Feb 27, 2013
@yckart Hey, here form the future to tell you that for (var prop in obj) if (obj[prop]) return false
will return false for additional properties on the prototype chain and this might not be the desired behavior; it would be wise to use for (var prop in obj) if (obj.hasOwnProperty(key) && obj[key]) return false
. Also jQuery, is this thing still around?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment