匹配中文字符的正则表达式:
[u4e00 - u9fa5];
匹配双字节字符(包括汉字在内):
[^\u0000-\u00ff]
匹配空行的正则表达式:
n[s|]\*r
匹配 HTML 标记的正则表达式:
/<(._)>._<\1>|<(.\*)\/>/;
匹配首尾空格的正则表达式:
/(^s*)|(s*$)/;
计算字符串的长度(一个双字节字符长度计 2 , ASCII 字符计 1 )
String.prototype.len = function(){
return this.replace([^x00-xff]/g,"aa").length;
}
匹配网址 URL 的正则表达式:
/http:/+([w-]+.)+[w-]+(/[w-./?% & =]\*)?/
匹配 E-mail 地址的正则表达式:
/w+([-+.]w+)_@w+([-.]w+)_.w+([-.]w+)\*/;
用正则表达式限制只能输入中文:
onkeyup = "value=value.replace(/[^u4E00-u9FA5]/g,'')";
onbeforepaste =
"clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))";
用正则表达式限制只能输入数字:
onkeyup = "value=value.replace(/[^d]/g,'')";
onbeforepaste =
"clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))";
用正则表达式限制只能输入数字和英文:
onkeyup = "value=value.replace(/[W]/g,'')";
onbeforepaste =
"clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))";
用正则表达式限制只能输入全角字符:
onkeyup = "value=value.replace(/[^uFF00-uFFFF]/g,'')";
onbeforepaste =
"clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))";
/^-\d+$/.test(str);
_str.value = _str.value.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, ''); // 正则替
window.onload = function () {
var _delHtmlTags = document.getElementById('delHtmlTags');
//获取元素对象
_delHtmlTags.onblur = function () {
//失去焦点
this.value = this.value.replace(/<[\/\!]*[^<>]*>/gi, '');
//过滤字符;
};
};
Validator = {
Require: /.+/, // 是否为空
Email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, // Email
Phone:
/^(?:(\(?:\d{2,3}\))|(\d{3}-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6-7}(-\d{1,4})?$/,
// 电话号码
Mobile: /^(?:(?:\(\d{2,3}\))|(?:\d{3}-))?13\d{9}$/, // 手机号码
Url: /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[/=?%-&_~`@[\]':+!]*([^<>""])*$/,
// 使用 HTTP 协议的网址
IdCard: 'this.IsIdCard(value)', //
Currency: /^\d+(\.\d+)?$/, // 货币
Number: /^\d+$/, // 数字
Zip: /^[1-9]\d{5}$/, // 邮政编码
QQ: /^[1-9]\d{4,12}$/, // QQ 号码
Integer: /^[-+]?\d+$/, // 整数
Double: /^[-+]?\d+(\.\d+)?$/, // 实数
English: /^[A-Za-z]+$/, // 英文
Chinese: /^[\u0391-\uFFE5]+$/, // 中文
Username: /^[a-z]\w{3,}$/i, // 用户名
UnSafe: /^(([A-Z]*|[a-z]*|\d*|[-_~!@#$%^&*.()[]{}<>\?\\\/'"]*)|.{0,5})$|\s/,
// 符合某规则的密码
};