I am trying to validate image files before they are uploaded using javascript/jquery.
Here is what I have so far:
$('#cropimages').click(function(){
i = 1 ;
var valid = new RegExp('/^.*\.(jpg|jpeg|png|gif)$/') ;
$('input').each(function(){
if($(this).attr('name') == 'file'+i)
{
val = $(this).val() ;
r = valid.exec(val) ;
alert(r) ;
i++ ;
}
})
//$('#topperform').submit()
})
But it keeps coming back null no matter what kind of file I choose.
What do I need to do to my RegExp to make this work?
var valid = /^.*\.(jpg|jpeg|png|gif)$/i;just in case your file contains extensions in uppercase like.JPG