Here, I will explain how to apply jQuery validation on File Upload control.
First of all I have put file upload control.
Here I have put jQuery function for check validation.
First of all I have put file upload control.
<input type="file" name="passportphoto" id="passportphoto" />
<input type="button" name="submit" id="submit" value="submit" onclick="return CheckValidation();" >
Here I have put jQuery function for check validation.
<script type="text/javascript">
var regex = /^([a-zA-Z0-9\s_\\.\-:\)\(])+(.jpg|.jpeg|.png|.pdf)$/;
function CheckValidation()
{
var passportphoto = $('#passportphoto');
if (passportphoto[0].files.length > 0) {
if (!regex.test(passportphoto[0].files[0].name.toLowerCase())) {
alert('Only .jpg|.jpeg|.png|.pdf files allowed.');
return false;
}
}
else
{
alert('Please select file.');
return false;
}
}
</script>
Comments
Post a Comment