How to filter which files can be seen on upload dialog box?

前端 未结 2 1934
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 17:52

In an ASP.NET MVC application which is not to have client side objects like ActiveXes, Flash or Java Applets (JavaScript is OK), is it feasible to imagine it being possible that

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 18:43

    You can't filter what files appear in the file upload dialog. This is browser-dependent and no browsers provide this functionality.

    However, once the file has been selected, it's value can be checked using JavaScript. You can handle the submit event of a form element and match the file input's value with a regular expression. Here's some untested sample code:

    
    
    

提交回复
热议问题