You need some parentheses to get the correct operator order:
if (!(val.contentType in ['image/jpeg', 'image/png', 'image/pjpeg', 'image/gif','image/bmp']))
Currently it's evaluating !val
first, and that's always true if it's not null or blank.