function checkEmail(email) { if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) { return true; } else { return false; } } function validateContactForm() { var subject = document.getElementById('subject'); var email = document.getElementById('email'); var message = document.getElementById('message'); if (email.value != "") { if (!checkEmail(email.value)) { alert("Вашият e-mail изглежда невалиден!"); email.focus(); return false; } } if (subject.value.length < 3) { alert("Моля попълнете заглавиете на Вашето съобщение!"); subject.focus(); return false; } if (message.value.length < 3) { alert("Моля попълнете заглавиете на Вашето съобщение!"); message.focus(); return false; } return true; }