175
rated 0 times
[
177]
[
2]
/ answers: 1 / hits: 79701
/ 12 Years ago, sun, may 6, 2012, 12:00:00
I need a regular expression to validate image file extensions in javascript. Do you have one ?
More From » regex
I need a regular expression to validate image file extensions in javascript. Do you have one ?
Could you explain the purpose?
Anyway here's one assuming you support few image types.
(/.(gif|jpe?g|tiff?|png|webp|bmp)$/i).test(filename)
I have put the whole regular expression within parentheses () so as to disambiguate between the slash (/) operator and RegExp object. See JSLint for more details.
Here's the raw regex as well.
/.(gif|jpe?g|tiff?|png|webp|bmp)$/i
This Regex also assumes that you're including the dot before the extension. Remove the .
if you're not.