PHP
·
发表于 5年以前
·
阅读量:8293
function getByteVal(val, max) {
var returnValue = '';
var byteValLen = 0;
for (var i = 0; i < val.length; i++) {
if (val[i].match(/[^\x00-\xff]/ig) != null)
byteValLen += 2;
else
byteValLen += 1;
if (byteValLen > max)
break;
returnValue += val[i];
}
return returnValue;
}
$('#txt').bind('keyup',function(){
var val=this.value;
if(val.replace(/[^\x00-\xff]/g,"**").length>14){
this.value=getByteVal(val,14)
}
})