$(document).ready(function(){ var form = $("#formInscription"); $("[type='submit']").click(function(e) { e.preventDefault(); var valid = true; $(".field-error", form).toggleClass("field-error", false); $("input.required, select.required", form).each(function() { if($(this).val() == "") { $(this).toggleClass("field-error", true); valid = false; } else { var regEmail = new RegExp("^([a-zA-Z0-9]+(([-\.\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[-\.\_])+[a-zA-Z]{2,4})$","g"); var email = $("#email", form).val(); if(!email.match(regEmail)) { $("#email").toggleClass("field-error", true); valid = false; } /* var regPostal = new RegExp("^[0-9]{5}$","g"); var postal = $("#postal", form).val(); if(!postal.match(regPostal)) { $("#postal").toggleClass("field-error", true); valid = false; } */ } }); if(valid) $(form).submit(); }); });