Regex To Check If Are Allowed File Types

A regular expression to check if the files you provide are allowed file types.

It is useful in file uploaders that allow you to validate file types before uploading.

Feel free to override the regex below to add more file extensions:

/\.(zip|tar|gif|jpe?g|tiff?|png|webp|bmp)$/i

Matches:

  • regext.zip
  • regex.gif
  • regex.webp

Non-matches:

  • regex.mp4
  • regex.mp3
  • regex.jiff

See Also: