Q:

How can i restrict user from not selecting other file types using input type file with react and typescript?

i want to restrict user from selecting files from select dialog other than .xml extensions.
i have code like below,
<input type='file' accept='.xml' onChange={handleselectedfile}/>

Now with this user can still change from .xml to All files and select the file.
How can i make sure or restrict user from  selecting files other than .xml extension types.
could someone help me with this. thanks.

A:

You can try to add a validation onChange
something like this for Javascript 

var fileName = document.getElementById('file').value.toLowerCase();
if(!fileName.endsWith('.xml'){
    alert('You can upload xml files only.');
    return false;
}

