var pytanie = { init: function(){ $('#form').bind('submit', function(){ return pytanie.walidacja(); }); }, walidacja: function(){ var ret = true; var blednePola = new Array(); var niepuste = new Array('#imie', '#nazwisko', '#email', '#telefon', '#pytanie'); var niepusteNazwy = new Array('imię', 'nazwisko', 'email', 'telefon', 'pytanie'); var emailRE = new RegExp("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$"); var telefonRE = new RegExp("^\\+?[0-9 \(\)]+$"); for (i in niepuste) { if ($(niepuste[i]).val().length < 3) { blednePola.push(niepusteNazwy[i]); ret = false; } } if (ret) // pola sa wypelnione { if (!$('#plec_m').attr('checked') && !$('#plec_k').attr('checked')) { blednePola.push('Pan/Pani'); ret = false; } if (!emailRE.test($('#email').val())) { blednePola.push('email'); ret = false; } if (!telefonRE.test($('#telefon').val())) { blednePola.push('telefon'); ret = false; } if (!$('#regulamin_zaakceptowany').attr('checked')) { blednePola.push('akceptacja regulaminu'); ret = false; } } if (!ret) { alert("Nie wszystkie obowiązkowe pola zostały wypełnione.\n\nPola zwaierające błędy:\n\n" + blednePola.join(', ') + "\n\n"); } return ret; }, fake: null }; $(document).ready(function() { pytanie.init(); });