Re: Regular Expression to validate file extension

From: bloomfield (bloomfield_at_as.ro)
Date: 06/18/04


Date: Fri, 18 Jun 2004 18:17:32 +0300

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

  • Regular Expression to validate file extension
    ... Does anyone know a regular expression that will validate the file extension ... but also allow multiple file extensions if necessary. ... Also I would like to check multiple file types, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Regular Expression to validate file extension
    ... "Chris Kennedy" wrote in message ... > but also allow multiple file extensions if necessary. ... > check if the extension is the correct type, i.e. .doc for a Word Document ... Also I would like to check multiple file types, ...
    (microsoft.public.dotnet.framework.aspnet)

Loading