I would like to remove all special characters (except for numbers) from a string. I have been able to get this far
var name = name.replace(/[^a-zA-Z ]/, "");
but it seems that it is removing the first number and leaving all of the others.
For example:
name = "collection1234"; //=> collection234
or
name = "1234567"; //=> 234567
Use the global flag:
var name = name.replace(/[^a-zA-Z ]/g, ""); ^
If you don't want to remove numbers, add it to the class:
var name = name.replace(/[^a-zA-Z0-9 ]/g, "");
1.4m articles
1.4m replys
5 comments
57.0k users