Use the string’s .replace
method with a regex of \D
, which is a shorthand character class that matches all non-digits:
myString = myString.replace(/\D/g,'');
More Related Contents:
- How do I make the first letter of a string uppercase in JavaScript?
- How do I replace a character at a particular index in JavaScript?
- Trim string in JavaScript?
- How to check if a string “StartsWith” another string?
- How to count string occurrence in string?
- Fastest method to replace all instances of a character in a string [duplicate]
- Evaluating a string as a mathematical expression in JavaScript
- How can I use backslashes (\) in a string?
- How many bytes in a JavaScript string?
- How can I split a string into segments of n characters?
- How to escape JavaScript in JSP?
- Use dynamic (variable) string as regex pattern in JavaScript
- Does console.log invokes toString method of an object?
- JavaScript string and number conversion
- Convert JavaScript String to be all lower case
- Efficient Javascript String Replacement
- Get the first integers in a string with JavaScript
- match() returns array with two matches when I expect one match
- Javascript string comparison fails when comparing unicode characters
- Find the characters in a string which are not duplicated
- jQuery call function from a string [duplicate]
- HEX to Base64 converter for JavaScript
- how to convert a string to a Unix timestamp in javascript?
- Are ES6 template literals faster than string concatenation?
- How Can I Truncate A String In jQuery?
- Javascript / Jquery – Get number from string
- How to test if a URL string is absolute or relative?
- Print / display a JavaScript variable’s name instead of it’s value
- How to count the number of lines of a string in javascript
- Does jQuery strip some html elements from a string when using .html()?