By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,812 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,812 IT Pros & Developers. It's quick & easy.

problem with regular expression validator on asp.net page

P: n/a
I'm having a problem with a regular expression in conjunction with the
regular expression validator. I am trying to make sure that when a user
browses for a file to upload, it ends in gif, jpeg or jpg. I have the
following expression which validates fine in a .net tester I use and
also a javascript tester. But when I use the following path on the
page, it gives me the error message that I haven't entered a valid
image.

(\.gif|\.jp[e]?g|\.png|\.JP[E]?G|\.GIF|\.PNG)$

C:\Documents and Settings\Geoff\Desktop\mypic.jpg

What am I doing wrong here?

Jul 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In news:11**********************@m79g2000cwm.googlegr oups.com,
vtxr1300 <ca********@hotmail.comwrote:
I'm having a problem with a regular expression in conjunction with the
regular expression validator. I am trying to make sure that when a
user browses for a file to upload, it ends in gif, jpeg or jpg. I
have the following expression which validates fine in a .net tester I
use and also a javascript tester. But when I use the following path
on the page, it gives me the error message that I haven't entered a
valid image.

(\.gif|\.jp[e]?g|\.png|\.JP[E]?G|\.GIF|\.PNG)$

C:\Documents and Settings\Geoff\Desktop\mypic.jpg

What am I doing wrong here?
A regular expression validator requires the regexp to match the whole input
field not just part of it. You are matching only the ending (file
extension). The following will do what you want:

..+(\.gif|\.jp[e]?g|\.png|\.JP[E]?G|\.GIF|\.PNG)$

In fact it will insist on the form filename.ext where ext is validated as
you have it and filename must be at list one character. As it is, it will
accept any character(s) for the name; you may want to change it to match
only characters that are legal in file name.
--
Jim
"Remember, an amateur built the Ark; professionals built the Titanic."
Jul 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.