Prueba esto. No diferencia entre mayúsculas y minúsculas. Se puede copiar y pegar:
// Javascript
function maxlength() {
var txtIni=document.getElementById("input1").value;
var txt=txtIni;
while(txt.length
- (txt.match(/\[:heart:\]/gi) || []).length*('[:heart:]'.length-1)
- (txt.match(/\[:heart:$/i) || []).length*('[:heart:'.length-1)
- (txt.match(/\[:heart$/i) || []).length*('[:heart'.length-1)
- (txt.match(/\[:hear$/i) || []).length*('[:hear'.length-1)
- (txt.match(/\[:hea$/i) || []).length*('[:hea'.length-1)
- (txt.match(/\[:he$/i) || []).length*('[:he'.length-1)
- (txt.match(/\[:h$/i) || []).length*('[:h'.length-1)
- (txt.match(/\[:$/i) || []).length*('[:'.length-1)
- (txt.match(/\[:foo:\]/gi) || []).length*('[:foo:]'.length-1)
- (txt.match(/\[:foo:$/i) || []).length*('[:foo:'.length-1)
- (txt.match(/\[:foo$/i) || []).length*('[:foo'.length-1)
- (txt.match(/\[:fo$/i) || []).length*('[:fo'.length-1)
- (txt.match(/\[:f$/i) || []).length*('[:f'.length-1)>10){
txt=txt.slice(0, -1);
}
if(txt!==txtIni)
document.getElementById("input1").value=txt;
};
document.getElementById("input1").onkeyup = maxlength;
function recortar() {
var txtIni=document.getElementById("input1").value;
var txt=txtIni;
while(txt.length
- (txt.match(/\[:heart:\]/gi) || []).length*('[:heart:]'.length-1)
- (txt.match(/\[:foo:\]/gi) || []).length*('[:foo:]'.length-1)>10){
txt=txt.slice(0, -1);
}
if(txt!==txtIni)
document.getElementById("input1").value=txt;
};
document.getElementById("input1").onblur = recortar;
// JQuery
$('#input2').on('keyup', function () {
var txtIni=$(this).val();
var txt=txtIni;
while(txt.length
- (txt.match(/\[:heart:\]/gi) || []).length*('[:heart:]'.length-1)
- (txt.match(/\[:heart:$/i) || []).length*('[:heart:'.length-1)
- (txt.match(/\[:heart$/i) || []).length*('[:heart'.length-1)
- (txt.match(/\[:hear$/i) || []).length*('[:hear'.length-1)
- (txt.match(/\[:hea$/i) || []).length*('[:hea'.length-1)
- (txt.match(/\[:he$/i) || []).length*('[:he'.length-1)
- (txt.match(/\[:h$/i) || []).length*('[:h'.length-1)
- (txt.match(/\[:$/i) || []).length*('[:'.length-1)
- (txt.match(/\[:foo:\]/gi) || []).length*('[:foo:]'.length-1)
- (txt.match(/\[:foo:$/i) || []).length*('[:foo:'.length-1)
- (txt.match(/\[:foo$/i) || []).length*('[:foo'.length-1)
- (txt.match(/\[:fo$/i) || []).length*('[:fo'.length-1)
- (txt.match(/\[:f$/i) || []).length*('[:f'.length-1)>10){
txt=txt.slice(0, -1);
}
if(txt!==txtIni)
$(this).val(txt);
}).on('blur',function(){
var txtIni=$(this).val();
var txt=txtIni;
while(txt.length
- (txt.match(/\[:heart:\]/gi) || []).length*('[:heart:]'.length-1)
- (txt.match(/\[:foo:\]/gi) || []).length*('[:foo:]'.length-1)>10){
txt=txt.slice(0, -1);
}
if(txt!==txtIni)
$(this).val(txt);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<input id="input1" type="text" style="width: 500px;">
<input id="input2" type="text" style="width: 500px;">
Saludos.