js正则表达式:如何替换字符串中的中文

JavaScript014

js正则表达式:如何替换字符串中的中文,第1张

楼上说的很好.

alert("L于O盼V盼E".replace(/([^\u0000-\u00FF])/g, function ($) { return escape($)}))

varmyReg = /^[a-zA-Z0-9_]{0,}$/ if(!myReg.test(input.val())) {   $.validation.tip(false, input, "用户名不能含有中文或特殊字符")   return } js通过正则表达式限制input输入框只能输入英文字母和数字,不能输入中文。 <input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"> 文本框中仅允许输入英文字母,小数点,数字,禁止输入中文字符以及其他特殊字符! <input type="text" name="username" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')" /> 输入大于0的正整数 <input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"> PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用: JavaScript正则表达式在线测试工具: http://tools.jb51.net/regex/javascript 正则表达式在线生成工具: http://tools.jb51.net/regex/create_reg var temp = 'abcdefg Fw:123456 Fw:789.1011' temp =temp.indexOf(‘.’)//匹配某个字符位置 alert(temp)��var temp = 'dsd-5555' temp =temp.replace('-','')//匹配某个字符必替换 alert(temp)