Strip all non-numeric characters from string in JavaScript -


Consider a non-dom scenario where you want to remove all non-numeric characters from the string using javascript / ECMAScript . Any characters that are in the range of 0-9 should be kept.

  var myString = 'abc123.8 & lt; Blah & gt; '; // The desired output is 1238  

How do you get it in plain JavaScript? Please remember this is a non-DOM scenario, so jQuery and other solutions that include browser and keypress events are not appropriate. Use the string method with a regex of

\ D Which is a miniature character square that matches all non-digits:

  myString = myString.replace (/ \ D / g, '');  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -