Re: Regular Expression to validate file extension
From: bloomfield (bloomfield_at_as.ro)
Date: 06/18/04
- Next message: Ryan Ternier: "Close a Pop up window with ASP.NET (VB)"
- Previous message: Raterus: "Re: Application folder"
- In reply to: Chris Kennedy: "Regular Expression to validate file extension"
- Next in thread: Chris Kennedy: "Re: Regular Expression to validate file extension"
- Reply: Chris Kennedy: "Re: Regular Expression to validate file extension"
- Messages sorted by: [ date ] [ thread ]
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. > >
- Next message: Ryan Ternier: "Close a Pop up window with ASP.NET (VB)"
- Previous message: Raterus: "Re: Application folder"
- In reply to: Chris Kennedy: "Regular Expression to validate file extension"
- Next in thread: Chris Kennedy: "Re: Regular Expression to validate file extension"
- Reply: Chris Kennedy: "Re: Regular Expression to validate file extension"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|