Last active
December 17, 2015 21:18
-
-
Save joseluisq/08c882914262d40557f0 to your computer and use it in GitHub Desktop.
Some jQuery utils functions
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
/** | |
* Some jQuery utils functions | |
*/ | |
(function($){ | |
$.fn.isEmpty=function(){ | |
return !!$(this).val()==null||$(this).val().length==0||/^\s+$/.test($(this).val()); | |
}; | |
$.fn.isEmail=function(){ | |
return !!(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test($(this).val())); | |
}; | |
$.fn.reset=function(){ | |
$(this).each(function(){ | |
this.reset(); | |
}); | |
}; | |
$.fn.clear=function(){ | |
if ($(this).is('input[type=text],textarea')) { | |
$(this).val(''); | |
} | |
}; | |
$.fn.disabled=function(){ | |
if($(this).is('form')){ | |
$('input,select,textarea,button',this).each(function(){ | |
$(this).attr('disabled',"-1"); | |
}); | |
} else if($(this).is('input,select,textarea,button')){ | |
$(this).attr("disabled","-1"); | |
} | |
}; | |
$.fn.enabled=function(){ | |
if($(this).is('form')){ | |
$('input,select,textarea,button',this).each(function(){ | |
$(this).removeAttr('disabled'); | |
}); | |
} else if($(this).is('input,select,textarea,button')){ | |
$(this).removeAttr('disabled'); | |
} | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment