$("#TextArea1").keydown(function(){
10            var curLength=$("#TextArea1").val().length;
11            if(curLength>=5){
12                var num=$("#TextArea1").val().substr(0,4);
13                $("#TextArea1").val(num);
14                alert("超过字数限制,多出的字将被截断!" );
15            }
16            else{
17                $("#textCount").text(4-$("#TextArea1").val().length)
18            }
19        })



            function num_check(){
                var obj= $(".bInput");
                var zhi=obj.val();
                var changdu=zhi.length;
                for(var i = 0; i < changdu; i++){
                    if(zhi.charCodeAt(i) > 127){
                        changdu++;
                    }
                }

                if(changdu>30){
                    alert("请输入2到15个汉字或4到30个英文,多出的字将被截断!" );
                    var num=$(".bInput").val().substr(0,15);
                    $(".bInput").val(num);
                }
            }


var reg =/^([a-zA-Z0-9_\-\.]{4,30}|[\u4E00-\u9FA5]{2,15})$/;
                if (!word.match(reg)) {
                    var msg = "只能输入汉字,英文字母,数字 -_.,且中文限制2到15个,英文限制4到30个";


计算字符串字节长度
 var wordlen= word.replace(/[^\x00-\xFF]/g,'**').length;