How to keep only small letters and numbers and remove other characters from string in JavaScript

1 Answer

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

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

console.log(s);



/*
run:

2a10a9f4chtam8vlh

*/

 



answered Jun 14, 2020 by avibootz
edited Mar 26, 2025 by avibootz
...