Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
23

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.


[#85753] Saturday, May 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dezmondhumbertob

Total Points: 79
Total Questions: 112
Total Answers: 107

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;