How to validate image file extension (jpg,png,gif,bmp) with JavaScript regular expression?
Asked
Active
Viewed 2.7k times
-17
-
http://stackoverflow.com/questions/10473185/regex-javascript-image-file-extension – AmmarCSE Apr 19 '15 at 16:50
1 Answers
10
Accordingly your issue the regular expression is quite simple.
/\.(jpe?g|png|gif|bmp)$/i
Do you really sure that nothing else will be used? For example, JPEG format allows both .jpg and .jpeg extensions. That's why I put e?
pattern in the regular expression.
Example of validation could be as follows:
var filename = "/site/images/test.png";
if ( /\.(jpe?g|png|gif|bmp)$/i.test(filename) ) {
. . .
.

jsxt
- 1,097
- 11
- 28
-
yes this is the regex, but how to validate the url, as example I have this path "/site/images/test.png". how to validate it ? – jobin Apr 19 '15 at 16:54