带有AllowMultiple属性的FIleUpload的RegularExpressionValidator

时间:2017-05-12 21:26:01

标签: c# asp.net regex file-upload

我有一个asp:FileUpload控件,AllowMultiple选项设置为true

<asp:FileUpload ID="ucFileUploader" runat="server" AllowMultiple="true" Accept=".jpg, .jpeg, .jpe, .gif, .pdf, .doc, .xls, .txt, .docx, .xlsx, .pptx, .ppt, .png, .one, .rtf"/>

我还有RegularExpressionValidator ValidationExpression来限制文件到特定的文件扩展名。

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationExpression="(.jpg|.jpeg|.jpe|.gif|.pdf|.doc|.xls|.txt|.docx|.xlsx|.pptx|.ppt|.png|.one|.rtf)"
                                    ControlToValidate="ucFileUploader" runat="server" ForeColor="Red" ErrorMessage="One or more of the files you selected has an invalid file type." Display="Dynamic" />

问题是RegularExpressionValidator似乎不会单独应用于每个文件名。

例如,如果我上传test1.txtbadfile.exe,则正则表达式将通过。如果我仅上传badfile.exe,则会失败。如果我上传`

如何编写正则表达式来验证多个文件?

请注意,这纯粹是出于客户端目的。

1 个答案:

答案 0 :(得分:-1)

相关问题