• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Regular Expression for only allowing certain file type

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
rito1
Asked:
rito1
  • 2
1 Solution
 
ozoCommented:
do your files match the ^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))
 +part?
0
 
rito1Author Commented:
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
 
jessc7Commented:
I think you could simplify it considerably, if you are only concerned with the extension:

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

Does tha work for you?
0
 
rito1Author Commented:
Thanks jessc7, that worked perfect.

Rit
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now