工作中用到的正则

<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">

只能输入英文
<input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">

文本框只能输入数字代码(小数点也不能输入)
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

只能输入数字,能输小数点
<input onkeyup="this.value=this.value.replace(/[^\d.]/g,'')">

只能输入字母和中文<input onkeyup="value=value.replace(/[\d]/g,'')">

只能输入字母和数字<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

//正整数
function isPInt(str) {
var g = /^[1-9]*[1-9][0-9]*$/;
return g.test(str);
}


匹配身份证:\d{15}|\d{18}
评注:中国的身份证为15位或18位


匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
评注:表单验证时很实用

猜你喜欢

转载自www.cnblogs.com/yazhng/p/8950239.html