连接:http: //www.cnblogs.com/tangge/p/4225870.html |
http: //blog.csdn.net/lybwwp/article/details/9028741 |
http: //blog.ny.cn/?p=389 |
***************************************************************************************************************************************** |
javascript: |
//验证手机号码的合法性 |
$.extend($.fn.validatebox.defaults.rules, { |
//移动手机号码验证 |
mobile: { //value值为文本框中的值 |
validator: function (value) { |
var reg = /^1[3|4|5|8|9]\d{9}$/; |
return reg.test(value); |
}, |
message: '输入手机号码格式不准确.' |
}, |
//验证汉子 |
CHS: { |
validator: function (value) { |
return /^[\u0391-\uFFE5]+$/.test(value); |
}, |
message: "" 只能输入汉字 "" |
}, |
|
faxno: { // 验证传真 |
validator: function (value) { |
// return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value); |
return /^(([Math Processing Error])|(\d{3}\-))?([Math Processing Error]|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value); |
}, |
message: '传真号码不正确' |
}, |
//国内邮编验证 |
zipcode: { |
validator: function (value) { |
var reg=/^[0-9]\d{5}$/; //以0至9的数字开头,后面接5位任意数字,\d就是任意数字的意思。 |
return reg.test(value); |
}, |
message: '邮编必须是6位数字.' |
}, |
//用户账号验证(只能包括 _ 数字 字母) |
account: { //param的值为[]中值 |
validator: function (value, param) { |
if (value.length < param[0] || value.length > param[1]) { |
$.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围' ; |
return false ; |
} else { |
if (!/^[\w]+$/.test(value)) { |
$.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.' ; |
return false ; |
} else { |
return true ; |
} |
} |
}, message: '' |
}, |
//验证网址的合法性 |
checkIp : { // 验证IP地址 |
validator : function (value) { |
var reg = /^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/ ; |
return reg.test(value); |
}, |
message : 'IP地址格式不正确' |
} |
|
}) |
***************************************************************************************************************************************** |
html页面: |
<html xmlns= "http://www.w3.org/1999/xhtml" > |
<head> |
<script src= "easyui1.2.4/jquery-1.6.min.js" type= "text/javascript" ></script> |
<script src= "easyui1.2.4/jquery.easyui.min.js" type= "text/javascript" ></script> |
<!--自定义验证--> |
<script src= "easyui1.2.4/validator.js" type= "text/javascript" ></script> |
<link href= "easyui1.2.4/themes/default/easyui.css" rel= "stylesheet" type= "text/css" /> |
<script> |
$( function () { |
|
//设置text需要验证 |
$( 'input[type=text]' ).validatebox(); |
}) |
|
</script> |
</head> |
<body> |
邮箱验证:<input type= "text" validtype= "email" required= "true" missingMessage= "不能为空" invalidMessage= "邮箱格式不正确" /><br /> |
网址验证:<input type= "text" validtype= "url" invalidMessage= "url格式不正确[http://www.example.com]" /><br /> |
长度验证:<input type= "text" validtype= "length[8,20]" invalidMessage= "有效长度8-20" /><br /> |
手机验证:<input type= "text" validtype= "mobile" /><br /> |
邮编验证:<input type= "text" validtype= "zipcode" /><br /> |
账号验证:<input type= "text" validtype= "account[8,20]" /><br /> |
汉子验证:<input type= "text" validtype= "CHS" /><br /> |
远程验证:<input type= "text" validtype= "remote['checkname.aspx','name']" invalidMessage= "用户名已存在" /> |
</body> |
</html> |
|
初级程序员
by: 云代码会员 发表于:2015-07-16 11:38:21 顶(0) | 踩(0) 回复
写的很详细
回复评论