[Solved] RegularExpression Validator for File Extension Validation in ASP.Net FileUpload

Last Reply one year ago By Mudassar

Posted one year ago

Hi,

using version asp.net 4.5


I am trying to validate file upload image validation and seems this expression is not working. The file name can be alphanumeric.
extention can be .jpeg|.JPEG|.gif|.GIF|.png|.PNG|.JPG|.jpg|.bitmap|.BITMAP

tried below two expresssion and both are not working.

 

ValidationExpression="=/^(([a-zA-Z0-9]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpeg|.JPEG|.gif|.GIF|.png|.PNG|.JPG|.jpg|.bitmap|.BITMAP)$/"

ValidationExpression="([a-zA-Z\\].*(.jpg|.png|.bmp|.jpeg|.gif|.tif)$)"

Code:

 

<asp:RegularExpressionValidator ID="regexUpload" runat="server" ErrorMessage="Upload Images only."
                                    ValidationExpression="([a-zA-Z\\].*(.jpg|.png|.bmp|.jpeg|.gif|.tif)$)"
                                    ValidationGroup="Submit"
                                    ControlToValidate="fileUpload1" ForeColor="Red"> </asp:RegularExpressionValidator>

sample file for i checkd :

 

12345.jpg

asd123.jpg

asdfg/jpg

anyhelp please

Posted one year ago

Try this one

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:RegularExpressionValidator ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.doc|.docx|.pdf)$"
    ControlToValidate="FileUpload1" runat="server" ErrorMessage="Please select a valid file." />
<asp:Button Text="Submit" runat="server" />

 

I agree, here is the link: http://e-iceblue.com/free-api