Home > Web Front-end > JS Tutorial > body text

Code to replace all characters except numbers and commas with js_javascript skills

WBOY
Release: 2016-05-16 16:45:27
Original
1968 people have browsed it

Replace all characters except numbers and commas with js

Copy code The code is as follows:


Result:

Copy code The code is as follows:

345345,345345


Full code:

Copy code The code is as follows:

FCKinsertdown.Add = function(strtemp,str) {
if(strtemp.indexOf(",")>-1){
strtemp=dostr(strtemp);
var strs= new Array(); //Define an array
strs=strtemp .split(","); //Character split
for (i=0;iif(i==strs.length){
FCK.InsertHtml( "[downsoft]" trim(strs[i]) "[/downsoft]") ;
}else{
FCK.InsertHtml("[downsoft]" trim(strs[i]) "[/downsoft]
") ;
}
}
}else{
FCK.InsertHtml("[downsoft]" dostr(strtemp) "[/downsoft]") ;
}
}

function dostr(str){
str=trim(str);
var strarry=unique(str.split(","));
str=strarry.join(",") ;
str=str.replace(/,/ig,",");
str=str.replace(/[^0-9,]*/ig,"");
str= str.replace(new RegExp(', ',"gm"),',');
if (str.substr(0,1)==',') str=str.substr(1);
var reg=/,$/gi;
str=str.replace(reg,"");
return str;
}

//Deduplicate array
function unique(data){
data = data || [];
var a = {};
len = data.length;
for (var i=0; i var v = data[i];
if (typeof(a[v]) == 'undefined'){
a[v] };         }
         return data;
}
//For users to call
function trim(s){
return trimRight(trimLeft(s));
}
//Remove the left whitespace
function trimLeft(s){
if(s == null) {
return "";
}
var whitespace = new String(" tnr");
var str = new String(s);
if (whitespace.indexOf(str.charAt(0)) != -1) {
var j=0, i = str.length;
while (j < i && whitespace.indexOf(str.charAt(j)) != -1){
j ;
}
str = str.substring(j, i);
}
return str;
}
//Remove the whitespace on the right
function trimRight(s){
if(s == null) return "";
var whitespace = new String(" tnr");
var str = new String(s);
if (whitespace.indexOf(str.charAt(str.length-1)) != -1){
var i = str. length - 1;
while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1){
i--;
}
str = str. substring(0, i 1);
}
return str;
}


Original article from Script House, please indicate the source when reprinting.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!