开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜