阿宽

Nothing is more powerful than habit!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Js 验证中文字符长度

Posted on 2013-08-13 16:46  宽田  阅读(651)  评论(0编辑  收藏  举报

代码如下:

  //Oracle Varchar2 一个中文对应3个Byte,所以用3个x替换
    var commentValue = commentValue.replace(/[^\x00-\xff]/g, "xxx");
    if (commentValue.length > 500) {
        alert("Max length is 150 Chinese or 500 English");
        return false;
    }