views:

48

answers:

1

i add asp.net file upload control as following

<asp:FileUpload ID="filesFileUpload" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" 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 .. could any help me why this done ?

A: 

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.

Oded
thnaks i used the following and it work good ValidationExpression="(.*?)\.(jpg|jpeg|png|gif)$"
Space Cracker