Home > Web Front-end > JS Tutorial > How to delete non-numeric characters in javascript

How to delete non-numeric characters in javascript

青灯夜游
Release: 2021-12-08 13:42:30
Original
7035 people have browsed it

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,'')".

How to delete non-numeric characters in javascript

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);
Copy after login

How to delete non-numeric characters in javascript

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template