常用校验的正则表达式
var rulesConfig = {
/**
* str.replace(/^\s+|\s+$/g, '')
解析:
str:要替换的字符串
\s : 表示 space ,空格
+: 一个或多个
^: 开始,^\s,以空格开始
$: 结束,\s$,以空格结束
|:或者
/g:global, 全局
/i 执行对大小写不敏感
/m 执行多行匹配
[abc]查找方括号之间的任何字符
[0-9]查找任何从0至9的数字
(x|y)查找任何以|分隔的选项
\d 查找数字
\s 查找空白字符
\b 匹配单词边界
\uxxxx 查找以十六进制数xxxx规定的Unicode字符
n+ 匹配任何包含至少一个n 的字符串
n* 匹配任何包含零个或多个n的字符串
n? 匹配任何包含零个或一个n的字符串
*/
email: {
validator: function(value){
return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(value);
},
message: '邮箱格式不对'
},

pass: {
validator: function(value){
return /^[!@#$%^&*a-zA-Z0-9_.]{6,15}$/.test(value);
},
message: '密碼格式不正確'
},

space: {//空格开头或者结尾匹配
validator: function(value){
return /^\s+|\s+$/.test(value);
},
message: '用户名不能以空格开头或者结尾'
},

idcard: { // 验证身份证
validator: function(value) {
return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
},
message: '身份证号码格式不正确'
},
minLength: {
validator: function(value, param) {
return value.length >= param[0];
},
message: '请输入至少(2)个字符.'
},
length: {
validator: function(value, param) {
var len = $.trim(value).length;
return len >= param[0] && len <= param[1];
},
message: "输入内容长度必须介于{0}和{1}之间."
},
phone: { // 验证电话号码
validator: function(value) {
return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message: '格式不正确,请使用下面格式:020-88888888'
},
mobile: { // 验证手机号码
validator: function(value) {
return /^(13|15|18)\d{9}$/i.test(value);
},
message: '手机号码格式不正确'
},
currency: { // 验证货币
validator: function(value) {
return /^\d+(\.\d+)?$/i.test(value);
},
message: '货币格式不正确'
},
decimal: {
validator: function(value, param) {
var regStr = "^\\d+(\\.\\d+)?$";
if(param)
regStr = "^\\+?(\\d*\\.\\d{" + param[0] + "})$";
var reg = new RegExp(regStr);
return reg.test(value);
},
message: '输入的数据格式不正确'
},
intOrFloat: { // 验证整数或小数
validator: function(value, param) {
var pattStr = "^\\d+(\\.\\d+)?$";
if(param) {
pattStr = "^\\d+(\\.\\d{0," + param[0] + "})?$";
}
return(new RegExp(pattStr)).test(value);
//如果有参数则验证小数的保留位数,下面是原正则表达式
//return /^\d+(\.\d+)?$/i.test(value);
},
message: '请输入数字,并确保格式正确'
},
integer: { // 验证整数
validator: function(value, param) {
var pattern = /^[+]?[0-9]+\d*$/i;
if(param)
pattern = new RegExp("^[0-9]\d{" + param[0] + "}$");
return pattern.test(value);
},
message: '请输入整数'
},
range: {
validator: function(value, param) {
var v1 = parseFloat(param[0]),
v2 = parseFloat(value),
v3 = parseFloat(param[1]);
if(isNaN(v1) || isNaN(v2) || isNaN(v3)) {
return false;
}
return(v1 <= v2 && v2 <= v3);
},
message: '请输入{0}到{1}之间的数字'
},
qq: { // 验证QQ,从10000开始
validator: function(value) {
return /^[1-9]\d{4,9}$/i.test(value);
},
message: 'QQ号码格式不正确'
},
age: { // 验证年龄
validator: function(value) {
return /^(?:[1-9][0-9]?|1[01][0-9]|120)$/i.test(value);
},
message: '年龄必须是0到120之间的整数'
},
chinese: { // 验证中文
validator: function(value, param) {

var pattern = new RegExp("^[\u4e00-\u9fa5]{" + param[0] + "," + param[1] + "}$");
return pattern.test(value);
//return /^[\Α-\¥]+$/i.test(value);
},
message: '请输入中文'
},
english: { // 验证英语
validator: function(value) {
return /^[A-Za-z]+$/i.test(value);
},
message: '请输入英文'
},
unnormal: { // 验证是否包含空格和非法字符
validator: function(value) {
return /.+/i.test(value);
},
message: '输入值不能为空和包含其他非法字符'
},
username: { // 验证用户名
validator: function(value) {
return /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){5,19}$/i.test(value);
},
message: '用户名不合法(字母开头,允许6-16字节,允许字母数字下划线)'
},
address: {
validator: function(value) {
var reg = /^[< >]+$/;
return !reg.test(value); //匹配是否含有特殊的字符
},
message: '只能输入包括汉字、字母、数字、符号'
},
faxno: { // 验证传真
validator: function(value) {
// return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value);
return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message: '传真号码不正确'
},
zip: { // 验证邮政编码
validator: function(value) {
return /^[1-9]\d{5}$/i.test(value);
},
message: '邮政编码格式不正确'
},
ip: { // 验证IP地址
validator: function(value) {
return /d+.d+.d+.d+/i.test(value);
},
message: 'IP地址格式不正确'
},
name: { // 验证姓名,可以是中文或英文
validator: function(value) {
return /^[\Α-\¥]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value);
},
message: '请输入姓名'
},
date: { // 验证姓名,可以是中文或英文
validator: function(value) {
//格式yyyy-MM-dd或yyyy-M-d
return /^(?:(?!0000)[0-9]{4}([-]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-]?)0?2\2(?:29))$/i.test(value);
},
message: '清输入合适的日期格式'
},
msn: {
validator: function(value) {
return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value);
},
message: '请输入有效的msn账号(例:abc@hotnail(msn/live).com)'
},
equals: {
validator: function(value, param) {
if($("#" + param[0]).val() != "" && value != "") {
return $("#" + param[0]).val() == value;
} else {
return true;
}
},
message: '两次输入的密码不一致!'
},
compareDate: {
validator: function(value, param) {
return dateCompare($(param[0]).datetimebox('getValue'), value); //注意easyui 时间控制获取值的方式
},
message: '开始日期不能大于结束日期'
},
linkMan: {
validator: function(value, param) {
var pattern = /^[\u4e00-\u9fa5]{2,4}$|^[a-zA-Z]{2,20}$/gi;
return pattern.test(value);
},
message: "请输入2-4个汉字或者20个字母"
},
phoneMobile: { //手机或者固话
validator: function(value, param) {
var pattern = /(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[358]\d{9})$)/;
return pattern.test(value);
},
message: "请输入固话或者手机号"
},
postCode: {
validator: function(value, param) {
//var pattern = /^[1-9]\d{5}$/;
var pattern = /^[0-9]\d{5}$/;
return pattern.test(value);
},
message: "请输入邮编"
},
product: {
validator: function(value, param) {
var pattern = new RegExp("^([\u4e00-\u9fa5]|[,]|[,]|[“]|[”]|[\"]|[\"]){" + param[0] + "," + param[1] + "}$");
return pattern.test(value);
},
message: "请输入主要产品"
},
companyCode: {
validator: function(value, param) {
var pattern = new RegExp("[a-zA-Z0-9]{8}-[a-zA-Z0-9]");
return pattern.test(value);
},
message: "请输入组织机构代码证"
},
flEmpty: {
validator: function(value, param) {
var reg = /^[\s ]|[ ]$/gi;
return !reg.yongshiyule178.com test(value);
//return !(/^\s+|\s+$/.test(value));
},
message: "首尾不能有空格"
},
timeDiff: { //时间范围验证
validator: function(value, param) {
//validType:'timeDiff[]'
if(param != undefined && param.length == 2) {
try {
var d1 = null,
curd = new Date(value.replace(/-/g, "/")),
d3 = null;
if(param[0] == 0) { //第一个参数=0 那么必须小于等于第二个参数
d3 = new Date(param[1].replace(/-/g, "/"));
rulesConfig.timeDiff.message = "您选择的时间必须大于等于{0}。";
return(curd <= d3);
} else if(param[1] == 0) { //第二个参数=0 那么必须大于等于第一个参数
d1 = new Date(param[0].replace(/-/g, "/"));
rulesConfig.timeDiff.message = "您选择的时间必须大于等于{0}。";
return(curd www.michenggw.com>= d1);
} else {
d1 = new Date(param[0].replace(/-/g, "/"));
d3 = new Date(param[1].replace(/-/g, "/"));
rulesConfig.timeDiff.message = "您选择的时间必须在{0}和{1}之间。";
return(d1 <= curd <= d3);
}
} catch(e) {
rulesConfig.timeDiff.message = "您选择的时间不正确。";
return false;

}

return false;
}
return true;

/* var d = new Date(value.replace(/-/g, "/"))
var d1 = null;
var d2 = null;
if (param[0] != undefined && param[www.dasheng178.com] != undefined) {//两个都不为空的时候需要在时间之间
d1 = new Date(param[0].replace(/-/g, "/"));
d2 = new Date(param[1].replace(/-/g, "/"));
return (d1 < d1 < d2);
} else if (param[1] != undefined) {//第二个参数不为空,则需要时间小于参数
d2 = new Date(param[1].replace(/-/g, "/"));
return (d < d2);
} else if (param[0] != undefined) {//第一个参数不为空,则需要时间大于参数
d1 = new Date(param[www.gouyiflb.cn].replace(/-/g, "/"));
return (d > d1);
}
return true;*/
},
message: "时间范围选择有误{0}{1}"
},
code: {
validator: function(value, param) {
var reg = new RegExp("<.*?script[^>]*?>.*?(<\/.*?script.*?>)*", "ig");
return !reg.test(value);
},
message: "您输入了非法危险字符"
}
};

Jquery常用正则验证的更多相关文章

  1. PHP常用正则验证

    手机号,身份证,ip验证 //正则验证手机号 正确返回 true function preg_mobile($mobile) { if(preg_match("/^1[34578]\d{9} ...

  2. Form 表单常用正则验证 (收藏)

    1.^\d+$ //匹配非负整数(正整数 + 0) 2.^[0-9]*[1-9][0-9]*$ //匹配正整数 3.^((-\d+)|(0+))$ //匹配非正整数(负整数 + 0) 4.^-[0-9 ...

  3. C#常用正则验证

    #region Protected Property protected Regex rLetters { get { return new Regex("[a-zA-Z]{1,}" ...

  4. C# 常用正则验证[转]

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  5. jquery里正则的使用方法及常用的正则验证

    本文是一篇关于jquery使用正则来验证输入,及一些常用验证规则的基础文章,适合新手. 假设我们的网页里有这样的一个表单: <input id="aijquery" type ...

  6. 常用表单验证&&常用正则

    ### 表单验证&&常用正则 ;(function(ELF){ ELF = ELF || (window.ELF = {}); var reg = {}, pattern = { /* ...

  7. jQuery常用插件与jQuery使用validation插件实现表单验证实例

    jQuery常用插件 1,jQuery特别容易扩展,开发者可以基于jQuery开发一些扩展动能 2,插件:http://plugins.jquery.com 3,超厉害的插件:validation . ...

  8. Java代码使用正则验证和常用工具方法

    1.正则验证邮箱 public static boolean checkEmail(String email){ boolean flag = false; try{ String check = & ...

  9. 【jquery】Validform,一款不错的 jquery 表单验证插件

    关于 Validform 这是一款很不错的 jquery 表单验证插件,它几乎能够满足任何验证需求,仅仅一行代码就能搞定整站的表单验证. $('form').Validform(); 为什么能如此方便 ...

随机推荐

  1. Ruby on Rails Tutorial 第2版 学习笔记

    Ruby on Rails Tutorial 第2版 在线阅读:http://railstutorial-china.org/ 英文版:http://ruby.railstutorial.org/ru ...

  2. AT+CGDCONT=0,"IP","ctnb"设置问题

    发现有的时候,设置不成功,经过验证正确的方法是,模组刚上电,或者刚复位的时候,先发送AT+CFUN=1,然后再去设置APN AT+CFUN= OK AT+CGDCONT=,"IP" ...

  3. 收集、分析线上日志数据实战——ELK

    本文来自网易云社区 作者:田躲躲 用户行为统计(User Behavior Statistics, UBS)一直是互联网产品中必不可少的环节,也俗称埋点.对于产品经理,运营人员来说,埋点当然是越多,覆 ...

  4. PHP调用wsdl接口实例化SoapClient抛出异常

    异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...

  5. Qt-第一个QML程序-1-项目工程的建立

    这个小程序是我发的第一个完整的QMl程序,这个程序也会持续的更新,一步一步的完善起来,最后会有一个什么样的结果也是不知道,只是把自己目前掌握的QML相关的东西都慢慢的写进来,积累起来 先展示一下运行结 ...

  6. 学好三角学(函数) — SWIFT和JAVASCRIPT游戏开发的必备技能 iFIERO.com

    不论是使用哪种平台进行开发,三角学在游戏当中都被广泛的使用,因此,小编iFERO认为,三角学是必须得掌握的技能之一. 游戏图片由 摘自 Razeware LLC 先以Javascript为例 一.角度 ...

  7. 用Python实现一个端口扫描,只需简单几步就好

    一.常见端口扫描的原理 0.秘密扫描 秘密扫描是一种不被审计工具所检测的扫描技术. 它通常用于在通过普通的防火墙或路由器的筛选(filtering)时隐藏自己. 秘密扫描能躲避IDS.防火墙.包过滤器 ...

  8. Spring Boot下的lombok安装 (日志) 不能识别log变量问题

    参考地址:http://blog.csdn.net/blueheart20/article/details/52909775 ps:除了要加载依赖之外 还要安装lombok插件

  9. Java三种编译方式

    Java程序代码需要编译后才能在虚拟机中运行,编译涉及到非常多的知识层面:编译原理.语言规范.虚拟机规范.本地机器码优化等:了解编译过程有利于了解整个Java运行机制,不仅可以使得我们编写出更优秀的代 ...

  10. iscroll手册

    概述: 大家在日常工作中最常用的插件是什么,jQurey?Lazyload?但是这些都是在PC端,但是在移动端最常用的插件莫过于iScroll了,iScroll到底是什么东西,应该怎么用?iScrol ...