Restrict file types on upload in jQuery
by barkkathulla[ Edit ] 2013-09-20 19:10:07
<input type="file" name="myimage" id="image" onchange="imagecheck()" /><br><span id='descerr' class='err'></span>
<span id='showoutput' class='err'></span>
function imagecheck()
{
var ext = $('#myimage').val().split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg']) == -1) {
alert('invalid extension!');
or
$('#showoutput').html("<font color='red'>choose valid image..</font>");//inline alert
return false;
}
}
from the above example ,
myimage -> id of file upload field