js中文字符的过滤问题

来源:互联网 发布:淘宝登录界面刷不出来 编辑:程序博客网 时间:2024/06/16 15:53
//返回中文<[^\x00-\xff]编码不在0-255的字符>String.prototype.len = function() {    return this.match(/[^\x00-\xff]/g);};//返回中文、英文混合字符串的字节长度【一个中文两个字节】<[^\x00-\xff]编码不在0-255的字符>String.prototype.len = function() {    return this.replace(/[^\x00-\xff]/g, '--').length;};