views:

18

answers:

2
                <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 validator even if the file is an image file, any ideas?

A: 

Try this will work :

^((i?)[a-z]|[^&])*\.(i?)jpg|\.png|\.jpeg|\.gif
c0mrade
A: 

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)$
Tim S. Van Haren