?
Solved

Regular Expression for only allowing certain file type

Posted on 2009-05-20
4
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

777 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