Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 123.1k

how to add a validation in fileuploader during onchange

Aug 29 2016 4:48 AM
how to add a validation in fileuploader during fileuploader onchange method it will accept only images with image preview??? 
 
I have a fileuploader in asp.net c#..I have already made a javascript function during fileuploader onchange method for image preview...
Here is my code for fileuplader
<asp:FileUpload ID="fileuploadimages" onchange="showimagepreview(this)" runat="server" />
<img src="" id="imgprvw" height="200">'
Here is my javascript code for imagepreview
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
function showimagepreview(input) {
debugger
if (input.files && input.files[0]) {
var filerdr = new FileReader();
filerdr.onload = function (e) {
$('#imgprvw').attr('src', e.target.result);
}
filerdr.readAsDataURL(input.files[0]);
}
}
</script>
Every thing is working fine..My problem is that i want to add a validation that
uploaded file only accept images not other file..how to modified my javasscript code that it will only accept images..if we will choose other file then fileuploader will become empty...can any one help me please??

Answers (8)