Solved

Regular Expression for only allowing certain file type

Posted on 2009-05-20
4
232 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

733 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