How to validate image file extension (jpg,png,gif,bmp) with JavaScript regular expression?
1 Answer
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) ) {
. . .
.
-
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 ?– jobinApr 19, 2015 at 16:54