Skip to content

Instantly share code, notes, and snippets.

@jacoborus
Created July 23, 2013 03:40
Show Gist options
  • Save jacoborus/6059681 to your computer and use it in GitHub Desktop.
Save jacoborus/6059681 to your computer and use it in GitHub Desktop.
Basic safe name for files
/* safe name for files */
var safeFilename = function ( name ) {
name = name.replace(/ /g, '-');
name = name.replace(/[^A-Za-z0-9-_\.]/g, '');
name = name.replace(/\.+/g, '.');
name = name.replace(/-+/g, '-');
name = name.replace(/_+/g, '_');
return name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment