Solved

Regular Expression for only allowing certain file type

Posted on 2009-05-20
4
227 Views
Last Modified: 2012-05-07
Hi All,

I have the following feable attempt to restrict my .net asp:FileUpload control to only allow JPG, GIF, and PNG files to be uploaded but it seems to not allow any files to be uploaded.

Please could someone suggest what I am doing wrong or an alternative expression?

Many thanks,

Rit
<asp:RegularExpressionValidator 

 id="RegularExpressionValidator1" runat="server" 

 ErrorMessage="Only jpg, png or gif files are allowed!" 

 ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))

    +(.jpg|.png|.gif)$" 

 ControlToValidate="FileUploadLogo"></asp:RegularExpressionValidator>

Open in new window

0
Comment
Question by:rito1
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24430608
do your files match the ^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))
 +part?
0
 
LVL 1

Author Comment

by:rito1
ID: 24430695
Ozo, I will be totally honest with you.. I haven't a clue what that statement means!

Basically I only want to allow .jpg, .gif and png files to be uploaded.

Rit
0
 
LVL 16

Accepted Solution

by:
jessc7 earned 500 total points
ID: 24431382
I think you could simplify it considerably, if you are only concerned with the extension:

^(.)+(.jpg|.png|.gif)$

Does tha work for you?
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 31583458
Thanks jessc7, that worked perfect.

Rit
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now