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

Last Reply on Feb 06, 2015 08:29 AM By Mudassar

Posted on Feb 06, 2015 08:29 AM

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 on Feb 06, 2015 08:29 AM

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: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html