I want To stop Form submit if i have selected wrong file in input file through js validation or from any other method .currently when i selected word file through file field it submit the form but return me the alert that this kind of file u can not upload and remove the input fields value how can i stop this ..
And js to stop wrong image file but its not working::
$("#profile_pic").change(function () {
var fileExtension = ['jpeg', 'jpg', 'png', 'gif'];
if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
alert("Only formats are allowed : "+fileExtension.join(','));
return false;
}
});