Substitua todos os caracteres, exceto números e vírgulas com JS
A cópia do código é a seguinte:
<Script Language = "JavaScript">
var str = "ASDFK, ASDF345345.345345";
// Substitua todos os caracteres, exceto números e vírgulas.
str = str.place (/[^0-9,]*/g, "");
// Remova a primeira vírgula
if (str.substr (0,1) == ',') str = str.substr (1);
// Remova a segunda vírgula
var reg =/, $/gi;
str = str.place (reg, "");
alerta (str);
</script>
resultado:
A cópia do código é a seguinte:
345345.345345
Código completo:
A cópia do código é a seguinte:
Fckinsertdown.add = function (strtemp, str) {
if (strtemp.indexof (",")>-1) {
strTemp = dostr (strTemp);
var strs = new Array (); // Defina uma matriz
strs = strtemp.split (","); // segmentação de caracteres
for (i = 0; i <strs.lengn; i ++) {
if (i == strs.length) {
Fck.inserthtml ("[Dowsoft]"+Trim (strs [i])+"[/downsoft]");
}outro{
Fck.inserthtml ("[dowsoft]"+Trim (strs [i])+"[ /downsoft] <r />");
}
}
}outro{
Fck.inserthtml ("[dowsoft]"+dostr (strtemp)+"[/downsoft]");
}
}
função dostr (str) {
STR = TRIM (STR);
var strarry = exclusivo (str.split (","));
str = STARRY.JOIN (",");
str = str.Replace (/,/ig, ",");
str = str.place (/[^0-9,]*/ig, "");
str = str.Replace (novo regexp (',+', "gm"), ',');
if (str.substr (0,1) == ',') str = str.substr (1);
var reg =/, $/gi;
str = str.place (reg, "");
retornar str;
}
// Array desduplicado
função exclusiva (dados) {
Dados = dados || [];
var a = {};
len = data.length;
for (var i = 0; i <len; i ++) {
var V = dados [i];
if (typeof (a [v]) == 'indefinido') {
a [v] = 1;
}
};
data.length = 0;
para (var i em a) {
dados [data.length] = i;
}
retornar dados;
}
// para os usuários ligarem
Função (s) {
Retornar Trimright (Trimleft (s));
}
// Remova o espaço em branco à esquerda
Função Trimleft (s) {
if (s == null) {
retornar "";
}
var whiteSpace = new String ("/t/n/r");
var str = nova (s) 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);
}
retornar str;
}
// Remova o espaço em branco à direita
Função Trimright (s) {
if (s == null) retornar "";
var whiteSpace = new String ("/t/n/r");
var str = nova (s) 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) {
eu--;
}
str = str.substring (0, i+1);
}
retornar str;
}
Artigos originais do wulin.com, indique a fonte ao reimprimir.