Check the Uploaded File is valid format in Javascript

Check the Uploaded File is valid format in JavaScript or JQuery

 

$('.doc_file_upload').on( 'change', function() {

        myfile= $( this ).val();

        var ext = myfile.split('.').pop();

        if(ext=="pdf" || ext=="docx" || ext=="doc"){

        } else{

             $( this ).val('');

            alert("Invalid Format");

        }

});