Use JS to replace all characters except numbers and commas
Copy Code code as follows:
<script language= "JavaScript" >
var str= "asdfk,asdf345345,345345";
Replaces all characters except numbers and commas.
Str=str.replace (/[^0-9,]*/g, "");
Remove the first comma
if (str.substr (0,1) = = ', ') str=str.substr (1);
Remove the second comma
var reg=/,$/gi;
Str=str.replace (Reg, "");
alert (str);
</script>
Results:
Copy Code code as follows:
Complete code:
Copy Code code 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 segmentation
for (i=0;i<strs.length; i++) {
if (i==strs.length) {
FCK. Inserthtml ("[Downsoft]" +trim (Strs[i]) + "[/downsoft]");
}else{
FCK. Inserthtml ("[Downsoft]" +trim (Strs[i]) + "[/downsoft]<br/>");
}
}
}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;
}
To repeat the array
function unique (data) {
data = Data | | [];
var a = {};
len = data.length;
for (var i=0; i<len;i++) {
var v = data[i];
if (typeof (A[v]) = = ' undefined ') {
A[V] = 1;
}
};
data.length=0;
for (var i in a) {
Data[data.length] = i;
}
return data;
}
For consumer calls
function Trim (s) {
Return TrimRight (Trimleft (s));
}
Remove the left blank
function Trimleft (s) {
if (s = = null) {
Return "";
}
var whitespace = new String ("\t\n\r");
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 blank on the right
function TrimRight (s) {
if (s = = null) return "";
var whitespace = new String ("\t\n\r");
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;
}
Cloud Habitat Community Original article, reproduced please indicate the source.