function isEmpty( val ) { switch (typeof(val)) { case 'string': return trim(val).length == 0 ? true : false; break; case 'number': return val == 0; break; case 'object': return val == null; break; case 'array': return val.length == 0; break; default: return true; } }; function trim( text ) { if (typeof(text) == "string") { return text.replace(/^\s*|\s*$/g, ""); } else { return text; } }