JavaScript: count minimal length of characters in text, ignoring special codes inside
Posted
by ilnur777
on Stack Overflow
See other posts from Stack Overflow
or by ilnur777
Published on 2010-04-07T15:09:20Z
Indexed on
2010/04/07
15:23 UTC
Read the original article
Hit count: 341
I want to ignore counting the length of characters in the text if there are special codes inside in textarea. I mean not to count the special codes characters in the text. I use special codes to define inputing smileys in the text. I want to count only the length of the text ignoring special code.
Here is my approximate code I tried to write, but can't let it work:
// smileys
// =======
function smileys(){
var smile = new Array();
smile[0] = "[:rolleyes:]";
smile[1] = "[:D]";
smile[2] = "[:blink:]";
smile[3] = "[:unsure:]";
smile[4] = "[8)]";
smile[5] = "[:-x]";
return(smile);
}
// symbols length limitation
// =========================
function minSymbols(field){
var get_smile = smileys();
var text = field.value;
for(var i=0; i<get_smile.length; i++){
for(var j=0; j<(text.length); j++){
if(get_smile[i]==text[j]){
text = field.value.replace(get_smile[i],"");
}
}
}
if(text.length < 50){
document.getElementById("saveB").disabled=true;
} else {
document.getElementById("saveB").disabled=false;
}
}
How the script should be in order to let it work? Thank you!
© Stack Overflow or respective owner