RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Image File Extension
Expression
.*(\.[Jj][Pp][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|\.[Pp][Nn][Gg])
Description
This expression should work to validate that an uploaded file's extension is either jpg, gif, or png.
Matches
foo.gif|foo.jpg|foo.png
Non-Matches
foo.txt|foo.zip|foo.exe
Author Rating: Not yet rated. Steven Smith
Source Willem @ Wildenborg.nl
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: clock
Name: chang won
Date: 6/17/2012 8:56:33 AM
Comment:
hi


Title: clock
Name: chang won
Date: 6/17/2012 8:56:25 AM
Comment:
hi


Title: Ok
Name: Denny
Date: 1/20/2008 10:07:10 PM
Comment:
You could add $ to the end of the expression to fix the security risk mentioned above. So it looks like: .*(\.[Jj][Pp][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg]|\.[Pp][Nn][Gg])$


Title: Sorta
Name: Dan
Date: 2/8/2007 3:29:32 PM
Comment:
doesn't check for (say) foo.jpg.exe , so it could be a security risk


Copyright © 2001-2014, RegexAdvice.com | ASP.NET Tutorials