Skip to content

Instantly share code, notes, and snippets.

@haydenbleasel
Created March 18, 2014 06:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haydenbleasel/9614813 to your computer and use it in GitHub Desktop.
Save haydenbleasel/9614813 to your computer and use it in GitHub Desktop.
Javascript filename sanitization
// Sanitize a filename. Try 'df.34.%)sdfE$t5.HF.mp4'
var extension = fileName.split('.').slice(0).pop(),
sanitized = filename.replace(extension, '').replace(/\W+/g, '') + "." + extension;
@gate3
Copy link

gate3 commented Dec 28, 2017

You should change filename to fileName though on the second line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment