$(document).ready(function(){ $('#form-submit').click(function(){ var fixFirst = false; var fixLast = false; var fixEmail = false; var fixPhone = false; var firstField = $('#edit-field-lead-name-und-0-value'); var lastField = $('#edit-field-last-name-und-0-value'); var emailField = $('#edit-field-lead-email-und-0-value'); var phoneField = $('#edit-field-lead-phone-und-0-value'); firstField.removeClass('error'); lastField.removeClass('error'); emailField.removeClass('error'); phoneField.removeClass('error'); var redo = false console.log("fristField.val() = " + firstField.val()); if(firstField.val().length < 2 || firstField.val().match(/[^a-z A-Z]/) != null){ fixFirst = true; redo = true; firstField.addClass('error'); } if(lastField.val().length < 2 || lastField.val().match(/[^a-z A-Z]/) != null){ lastField.addClass('error'); fixLast = true; redo = true; } if(emailField.val().match(/./) == null || emailField.val().match(/@/) == null){ emailField.addClass('error'); fixEmail = true; redo = true; } if(phoneField.val().match(/[^-\(\)0-9]/) != null || phoneField.val().length < 9){ phoneField.addClass('error'); fixPhone = true; redo = true; } if(redo == true){ $('#node_lead_form_group_general_information').show(0); $('#node_lead_form_group_preferences').hide(0); } return false; }) })