Please see note before copying my code>>
//CHECK TYPE OF PASSED OBJ:
function is(obj,type){
switch(type){
case 'array': case 'ar': //ARRAY:
return(String(obj.constructor).indexOf('Array')>-1)
break;
case 'integer': case 'int': case 'number': //NUMBER:
return((parseFloat(obj) == parseInt(obj)) && !isNaN(obj))
break;
default: //IS EMPTY:
if(obj==null || obj==undefined || obj==' ' || obj==0 || obj==false || obj=="false" || obj=='' || obj=="\n") return(false);
return(true)
}
}
/*EXAMPLES:
returns true if myvar is a positive value (string, number, array, DOM element, etc):
if(is(myvar)){..continue with function...}
returns true if myvar is an array:
if(is(myvar,'array')){..continue with function...}
returns true if myvar is an integer or can be converted to an integer:
if(is(myvar,'int')){..continue with function...}
*/
//CHECKS IF ANY OF THE PASSED ARG(S) ARE BLANK OR FALSE OR 0 OR UNDEFINED:
function isempty(){
for (var i = 0; i < arguments.length; i++) {
if(!is(arguments[i])){return(true)}
}
return(false)
}
/*EXAMPLE:
if(isempty(requiredVar1,requiredVar2,requiredVar3)){
return(false);
}else{...continue with function...}
*/

No comments:
Post a Comment