views:

26

answers:

1

Hay guys, i need help with a REGEX.

I have the got the value of an input box with this.

fileext = filename.split(".").reverse()[0];

I need to make sure this is a jpg, gif or png. Else throw an error.

Thanks

+4  A: 

Try using only regular expressions:

/\.(jpe?g|png|gif)$/i.test(filename);

This will check that the string ends with the correct extension.

Rowan Lewis
Thank you very much!
dotty