$(function(){ $("#leadactionform").submit(function(){ var err; $("#leadactionform :input[data-mand^='y']").each(function(){ $input = ($(this).closest("td").prev().clone().children().remove().end().text()).replace(":",""); if( $.trim($(this).val()) == "") { $("#"+$(this).attr('name')+"err").html(""+$input+" is mandatory field."); err = 1; } if($(this).attr('name') == "PrimaryEmail" && $(this).val()!= "") { emailID = $(this).val(); atpos = emailID.indexOf("@"); dotpos = emailID.lastIndexOf("."); if (atpos < 1 || ( dotpos - atpos < 2 )) { $("#"+$(this).attr('name')+"err").html("Please enter correct email."); err = 1; } } }); if(err == 1) return false; else return true; }); });