Regular Expression To Match Valid Filename

A regular expression to match valid filenames. Can be used to validate filenames entered by a user of an application, or the filename of files uploaded from a scanner.

/^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\.[a-zA-Z0-9_-]+$/

View Details