$(document).ready(function() { $("#btnSubmit").click(function() { var message = ''; if ($("#name").val() == '' || $("#address").val() == '' || $("#area").val() == '' || $("#phone").val() == '' || $("#date").val() == '' || $("#comments").val() == ''|| $("#telephone").val() == ''|| $("#email").val() == '') { message = "Please add required details."; alert(message); return false; } var phone = $('input[name="phone"]').val(), intRegex = /[0-9]/; if ((phone.length != 10) || (!intRegex.test(phone))) { $('input[name="phone"]').focus(); message = "Please enter a valid Contact Number."; alert(message); return false; } if ($("#telephone").val() != '') { var phone = $('input[name="telephone"]').val(), intRegex = /[0-9]/; if ((phone.length != 10) || (!intRegex.test(phone))) { $('input[name="telephone"]').focus(); message = "Please enter a valid Alternate Number."; alert(message); return false; } } if ($("#email").val() != '') { if (!isValidEmailAddress($("#email").val())) { message = "Please enter the valid Email Id"; alert(message); return false; } } }); function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); return pattern.test(emailAddress); }; });