Skip to content

Instantly share code, notes, and snippets.

@saxap
Last active August 29, 2015 14:25
Show Gist options
  • Save saxap/2dab9493ec6bdae987a9 to your computer and use it in GitHub Desktop.
Save saxap/2dab9493ec6bdae987a9 to your computer and use it in GitHub Desktop.
simple bootstrap form validation on jquery
function checkErrors(el) {
var errors = false
el.find('input, textarea').each(function(){
if ($(this).val() == '') {
$(this).closest('.form-group').addClass('has-error');
errors = true;
} else {
$(this).closest('.form-group').removeClass('has-error');
}
});
if (errors) return true;
else return false;
}
//////////
$('form').submit(function(e){
var form = $(this);
if (checkErrors(form)) return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment