Well firstly Javascript would be pointless to use on the file input, as its disabled for security reasons on pretty much every modern browser.
To do what your actually talking about, restricting it to certain file types on the file browsing window it self, you’ll want to look into the “accept” attribute, which you can specify a mimetype to restrict it to certain files. (you might also be able to seperate them with something, i think a semicolon to do multiple file types)
Information on the accept attribute .
EDIT: i forgot to mention, you should not use only this for checking the file type, some browsers dont support it.