String.prototype.getBytes = function() { var cArr = this.match(/[^\x00-\xff]/ig); return this.length + (cArr == null ? 0 : cArr.length); } function CheckForm(str){ if(str.value.getBytes() > 64){ alert("字符超过64个字符"); return false; } return true; }
getBytes用正则表达式来判断字符串中包含汉字的个数,包含的汉字都放到数组cArr中,这样cArr的长度就是汉字的总数。getBytes方法返回length加上汉字数,就是总的字节数...