开发者

File Upload Validator always show error message

开发者 https://www.devze.com 2022-12-23 16:07 出处:网络
I add asp.net file upload control as follows: <asp:FileUpload ID=\"filesFileUpload\" runat=\"server\" />

I add asp.net file upload control as follows:

<asp:FileUpload ID="filesFileUpload" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionV开发者_JAVA技巧alidator3" runat="server" ErrorMessage="file types not supported"
ValidationExpression="\.(zip|rar|jpg|gif|png|eps|ai|psd|pdf)$" ControlToValidate="filesFileUpload"></asp:RegularExpressionValidator>

And always when I upload file that match the reg expression it show the error. How can I resolve this?


Your regular expression checks for a single dot, followed by one of the extensions, all the way to the end of the string. You need to match the rest of the the filename (.+ matches one or more characters , ^ mean start of string):

ValidationExpression="^.+\.(zip|rar|jpg|gif|png|eps|ai|psd|pdf)$"

See this handy cheat sheet.

0

精彩评论

暂无评论...
验证码 换一张
取 消