File Upload Validator always show error message
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.
精彩评论