JSFiddle - React, Tailwind, and code Playground

by Iftakharul Alam

HTML

<input type="file" name="file1" class="file" accept="image/jpeg, image/x-png"/>

JavaScript

function check(obj){
    var fileExtension = ['jpeg', 'jpg', 'png'];
    if ($.inArray($(obj).val().split('.').pop().toLowerCase(), fileExtension) == -1){
        alert("Only '.jpeg','.jpg', '.png' formats are allowed.");
        $('.file').val('');
    }
        
}
$('.file').on('change',function(){
    check($(this));
});