prcaen prcaen - 2 days ago 4
Javascript Question

Regex JavaScript image file extension

I need a regular expression to validate image file extensions in javascript. Do you have one ?

Answer

Could you explain the purpose?

Anyway here's one assuming you support few image types.

(/\.(gif|jpg|jpeg|tiff|png)$/i).test(filename)

I have put the whole regular expression within parens () so as to disambiguate between the slash (/) operator and RegExp object. See JSLint for more details.

Comments