Skip to content

Instantly share code, notes, and snippets.

@arpitr
Created January 19, 2016 06:12
Show Gist options
  • Save arpitr/08118e59ff1dfba88556 to your computer and use it in GitHub Desktop.
Save arpitr/08118e59ff1dfba88556 to your computer and use it in GitHub Desktop.
Regular Expression for safe file name input by user.
// ^ matches the beginning of the string.
// \w matches a "word" character (A-Z, a-z, 0-9, and _ only).
// The "+" sign means "one or more."
// \. matches a single dot.
// And the final $ matches the end of the string.
$safeFilename = '/^\w+\.\w+$/';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment