Created
May 19, 2014 17:53
-
-
Save tcelestino/d3aeb0855d43be3938fe to your computer and use it in GitHub Desktop.
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 valida(selector, show_errors) { | |
var show_errors = (show_errors!=undefined)?show_errors:true; | |
var validaForm = true; | |
/*var $input = $("input[type=email]").val(); | |
var _reg = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | |
if(!_reg.test($input)) { | |
alert("digite um email válido"); | |
};*/ | |
$(selector).find("input, textarea, select").each(function() { | |
var $field = $(this); | |
var $exe = $('.exe'); | |
var $error = $field.parents("li:first").find(".erro"); | |
var _val = ($field[0].tagName == "SELECT")?$field.find("option:selected").val():$field.val(); | |
if ($.trim(_val) == '' && $error.size()>0) { | |
if(show_errors) { | |
$field.addClass("erro-campo"); | |
$error.fadeIn(); | |
$exe.hide(); | |
$field.focus(function() { | |
$field.removeClass("erro-campo"); | |
$error.fadeOut(); | |
}); | |
} | |
validaForm = false; | |
} | |
}); | |
return validaForm; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment