123
rated 0 times
[
124]
[
1]
/ answers: 1 / hits: 26310
/ 9 Years ago, sun, april 19, 2015, 12:00:00
How to validate image file extension (jpg,png,gif,bmp) with JavaScript regular expression?
More From » regex
How to validate image file extension (jpg,png,gif,bmp) with JavaScript regular expression?
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) ) {
. . .
.