Use js to replace all characters except numbers and commas
Copy codeThe Code is as follows:
<Script language = "javascript">
Var str = "asdfk, asdf345345, 345345 ";
// Replace 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>
Result:
Copy codeThe Code is as follows:
345345, 345345
Complete code:
Copy codeThe Code is as follows:
FCKinsertdown. Add = function (strtemp, str ){
If (strtemp. indexOf (",")>-1 ){
Strtemp = dostr (strtemp );
Var strs = new Array (); // defines an Array
Strs = strtemp. split (","); // delimiter
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;
}
// Deduplication 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 ){
Data [data. length] = I;
}
Return data;
}
// For the user to call
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 white space 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;
}
The original Article of the script home. For more information, see the source.