Skip to content

Instantly share code, notes, and snippets.

@jonesch
Created September 20, 2013 13:13
Show Gist options
  • Save jonesch/6637312 to your computer and use it in GitHub Desktop.
Save jonesch/6637312 to your computer and use it in GitHub Desktop.
Generic JS Form validation
$('.general-contact-form').submit(function(){
var req_values = ['user_name', 'user_email_address', 'user_phone_number', 'user_interest_in'],
empty_fields = false;
for (var i = 0; i < req_values.length; i++) {
if($('#'+req_values[i]).val() == ''){
$('#'+req_values[i]).addClass('required');
empty_fields = true;
}
}
if(empty_fields === true || ){
log('you have some empty values');
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment