Javascript regex, replace all characters other than numbers

You need the /g modifier to replace every occurrence:

"a100.dfwe".replace(/[^0-9]+/g, "");

I also removed the redundant i modifier and the unused capturing sub-expression braces for you. As others have pointed out, you can also use \D to shorten it even further:

"a100.dfwe".replace(/\D+/g, "");

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)