I'm doing validation first on an email(mandatory and correct format) and then on a file upload(either blank or correct format) on the button submit.
Here the email is validating well but in file upload if it is blank it also shows an error which is not needed.
Code:
<script type="text/javascript">
$(document).ready(function () {
$("#button").click(function () {
var email = $("#person_email").val();
var img = $("#person_avatar").val();
if (email == null || email == "" || !email.match(/^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/))
{
$("#valid").show();
return false;
} else if (!img == "" || !img.match(/(\.bmp|\.png|\.jpg|\.jpeg|\.gif)$/))
{
$("#valid_1").show();
return false;
} else {
return true;
}
});
});
</script>