tags:

views:

50

answers:

2

I'm trying to remove any character except 0-9 a-z A-Z....

var file_name = file.name;
file_name = file_name.replace(/[^A-Z0-9\._\-]/i, '');

any obvious reason the above isn't working?

+12  A: 

You need to specify the global-flag on your regular expression. Otherwise, only the first occurrence will be replaced:

file_name = file_name.replace(/[^A-Z0-9\._\-]/gi, '');
elusive
thanks, forgot about that!
Haroldo
You're welcome ;)
elusive
A: 

Give Regexr a go. Hover over the check boxes under the text box at the top to see the options you have. Look at the bottom pane to see the generated Regex.

cofiem