Detailed explanation of JS removal of all commas in string

小云云
Release: 2018-01-09 13:31:51
Original
3233 people have browsed it

本文主要介绍了JS去掉字符串中所有的逗号,需要的朋友可以参考下,希望能帮助到大家。

1、去掉所有字符串里面所有的逗号,eg:123,111,222.00——123111222.00

function clear(str) { str = str.replace(/,/g, "");//取消字符串中出现的所有逗号 return str; }
Copy after login

2、判断不是数字的

isNaN 函数

isNaN(expression:Object) : Boolean

计算参数,如果值为 NaN(非数字),则返回 true。此函数可用于检查一个数学表达式是否成功地计算为一个数字。

可用性:Flash Player 5;ActionScript 1.0

参数

expression:Object - 要计算的布尔值、变量或其它表达式。

返回

Boolean - 一个布尔值。

例子:

if(isNaN(document.login.imgcode.value)){ alert('验证码必须是数字!') document.login.imgcode.focus(); return false; }
Copy after login

3、replaceAll

Copy after login

PS:js去除字符串中所有 和&等特殊符号

var a="今天是星期五, 明天又可以放假了&好好休|息一下"; var converter = document.createElement("p"); converter.innerHTML = a; var b = converter.innerText; converter = null; var c=b.replace(/[&\|\\\*^%$#@\-]/g,""); alert(c);
Copy after login

相关推荐:

js去字符串前后空格5种实现方法及比较_javascript技巧

js去字符串前后空格的实现方法_javascript技巧

js字符串中含有数字与特殊字符应该如何判断?

The above is the detailed content of Detailed explanation of JS removal of all commas in string. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!