0

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

1 Answer 1

5

Try using only regular expressions:

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.