Home >Web Front-end >JS Tutorial >How to delete non-numeric characters in javascript
In js, you can use the replace() function with the regular expression "/[^0-9]/g" or "/[^\d]/g" to delete non-numeric characters, syntax "str.replace(/[^0-9]/g,'')" or "str.replace(/[^\d]/g,'')".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, you can use the replace() function with regular expressions to delete non-numeric characters.
Thereplace() method is used to replace some characters with other characters in a string, or replace a substring that matches a regular expression.
Example:
var str="0123kj45j67u89"; var nstr = str.replace(/[^0-9]/g,''); // var nstr = str.replace(/[^\d]/g, ''); console.log(nstr);
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to delete non-numeric characters in javascript. For more information, please follow other related articles on the PHP Chinese website!