Problem with fileupload only allowing images
<asp:RegularExpressionValidator
id="RegularExpressionValidator1" runat="server"
ErrorMessage="Only images are allowed!"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))
+(.jpg|.JPG|.gif|.GIF|.png|.PNG|.jpeg|.JPEG)$"
ControlToValidate="fileUpEx"></asp:RegularExpressionValidator>
<asp:FileUpload ID="fileUpEx" runat="server" />
Whatever file I pick, this throws the vali开发者_C百科dator even if the file is an image file, any ideas?
There is no guarantee that the browser will insert the full client path to the file into the input field. Some browsers only show the file name itself. You're better off using a regular expression that tests for just a file extension.
Give this one a try:
^?($(i?)jpg|\.png|\.jpeg|\.gif)$
Try this will work :
^((i?)[a-z]|[^&])*\.(i?)jpg|\.png|\.jpeg|\.gif
精彩评论