Remove all characters but digits from string – JavaScript

The following regular expression will match for a single character not present in the range between 0 (ASCII 48) and 9 (ASCII 57) (case sensitive).

Meaning it will convert from Test123 to Test.

myString = myString.replace(/[^0-9]/g, '');

Reading material

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.
One comment

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*