Re: Regular Expression to validate file extension

From: Chris Kennedy (nospam_at_nospam.co.uk)
Date: 06/19/04


Date: Sat, 19 Jun 2004 14:17:25 +0100

It tried putting this in the validation expression of my regular expression
validator, got it to validate a textbox with qwerty.jpg as the text value
and it didn't work. Any ideas? Regards, Chris.

"bloomfield" <bloomfield@as.ro> wrote in message
news:#KRWWfUVEHA.712@TK2MSFTNGP11.phx.gbl...
> Here there are some clues
>
> string checkFileRegex = @"^.+\.((jpg)|(gif)|(jpeg))$";
>
> string[] testData = new string[]
> {
> @"D:\My\download\test1.gif",
> @"D:\My\download\test2.cmd",
> "TeSt3.jPg",
> "test4.opp",
> "test5.JPG",
> "test6.gIn",
> "test7.again.jpeg",
> "nothing"
> };
>
> foreach(string test in testData)
> {
> if( Regex.IsMatch(test, checkFileRegex, RegexOptions.Multiline |
> RegexOptions.IgnoreCase ))
> {
> System.Diagnostics.Debug.WriteLine(string.Format("{0} OK", test));
> }
> else
> {
> System.Diagnostics.Debug.WriteLine(string.Format("{0} NOT OK", test));
> }
> }
>
> Hope this helps
>
> --
> ____________________
> www.bloomfield.as.ro
>
> Chris Kennedy wrote:
> > Does anyone know a regular expression that will validate the file
extension
> > but also allow multiple file extensions if necessary. It also needs to
be
> > case insensitive. Basically, what I want is to validate a file input box
to
> > check if the extension is the correct type, i.e. .doc for a Word
Document
> > etc. Also I would like to check multiple file types, for instance allow
a
> > gif or a jpeg or a jpg.
> >
> > Regards, Chris.
> >
> >



Relevant Pages

  • Re: Regular Expression to validate file extension
    ... expressions in the extension of a file path e.g. jpeg or jpg or gif. ... what I want is to validate a file input box ... Also I would like to check multiple file types, ... >> Regards, Chris. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: validate email and checks blank as well
    ... going to have more regular expression don't want to use both(require and ... I have all the controls formattted via HTML so they show on the page nice ... I've other controls which i use requirevalidator in the same column, ... textbox to validate and your done. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: regexp problems
    ... my procedure was just to validate an entry widget., ... %substitution "%S". ... your regular expression failed i.e. the expression does not cover ...
    (comp.lang.tcl)
  • Re: What do you need to have to be considered a Master at Perl?
    ... Write a regular expression to ... validate it and capture a usable phone number. ... regurgitated to a human for the human to use, I'd by inclined to not validate at all, present it to the human as is and let the human do whatever validation/interpretation may be needed. ... candidate has a grasp of basic regular expressions: programmers who are ...
    (comp.lang.perl.misc)
  • Re: packing things back to regular expression
    ... I want to do the reverse of reg-exp match. ... Are you trying to validate the data against the regular expression as ... and extract the string it was ...
    (comp.lang.python)