How to keep only letters and numbers (a-zA-Z 0-9) and remove other characters from string in JavaScript

1 Answer

0 votes
s = '2a1-0/R@a9f#4K$$cCK^htPam8vlwhJ'

s = s.replace(/[^a-zA-Z0-9]+/g, "");

console.log(s);



/*
run:

2a10Ra9f4KcCKhtPam8vlwhJ

*/

 



answered Jun 14, 2020 by avibootz
...