easyUI validate函数【总结篇-部分转】
以下是自己總結(jié)和修改別人的帖子和資源整理出來(lái)的一些常用驗(yàn)證函數(shù),備用,交流。
<body>
郵箱驗(yàn)證:<input type="text" validtype="email" required="true" missingMessage="不能為空" invalidMessage="郵箱格式不正確" /><br />
網(wǎng)址驗(yàn)證:<input type="text" validtype="url" invalidMessage="url格式不正確[http://www.example.com]" /><br />
長(zhǎng)度驗(yàn)證:<input type="text" validtype="length[8,20]" invalidMessage="有效長(zhǎng)度8-20" /><br />
1 漢字驗(yàn)證:<input type="text" validtype="CHS" /><br />
2 手機(jī)驗(yàn)證:<input type="text" validtype="mobile" /><br />
3 phone驗(yàn)證:<input type="text" validtype="phone" /><br />
4 ip驗(yàn)證:<input type="text" validtype="ip" /><br />
5 name驗(yàn)證:<input type="text" validtype="name" /><br />
6 username驗(yàn)證:<input type="text" validtype="username" /><br />
7 date驗(yàn)證:<input type="text" validtype="date" /><br />
8 english驗(yàn)證:<input type="text" validtype="english" /><br />
9 郵編驗(yàn)證:<input type="text" validtype="zipcode" /><br />
10 身份證驗(yàn)證:<input type="text" validtype="idcard" /><br />
11 minLength驗(yàn)證:<input type="text" validtype="minLength[3]" /><br />
12 intOrFloat驗(yàn)證:<input type="text" validtype="intOrFloat" /><br />
13 qq驗(yàn)證:<input type="text" validtype="qq" /><br />
14 integer驗(yàn)證:<input type="text" validtype="integer" /><br />
15 年齡驗(yàn)證:<input type="text" validtype="age" /><br />
16 unmormal驗(yàn)證:<input type="text" validtype="unnormal" /><br />
17 傳真驗(yàn)證:<input type="text" validtype="faxno" /><br />
19 數(shù)字驗(yàn)證:<input type="text" validtype="number" /><br />
20 車牌驗(yàn)證:<input type="text" validtype="carNo" /><br />
21賬號(hào)驗(yàn)證:<input type="text" validtype="account[8,20]" /><br />
遠(yuǎn)程驗(yàn)證:<input type="text" validtype="remote['checkname.aspx','name']" invalidMessage="用戶名已存在"/>
</body>
<script>
$(function () {
//設(shè)置text需要驗(yàn)證
$('input[type=text]').validatebox();
//自定義validator.js
//擴(kuò)展easyui表單的驗(yàn)證
$.extend($.fn.validatebox.defaults.rules, {
//1.驗(yàn)證漢字
CHS: {
validator: function (value) {
return /^[\u0391-\uFFE5]+$/.test(value);
},
message: '只能輸入漢字'
},
//2.移動(dòng)手機(jī)號(hào)碼驗(yàn)證
mobile: {//value值為文本框中的值
validator: function (value) {
var reg = /^1[3|4|5|8|9]\d{9}$/;
return reg.test(value);
},
message: '輸入手機(jī)號(hào)碼格式不準(zhǔn)確.'
},
//3.電話號(hào)碼驗(yàn)證
phone: {// 驗(yàn)證電話號(hào)碼
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: '格式不正確,請(qǐng)使用下面格式:020-88888888'
},
?
//4.驗(yàn)證IP
ip: {// 驗(yàn)證IP地址
validator: function (value) {
return /\d+\.\d+\.\d+\.\d+/.test(value);
},
message: 'IP地址格式不正確'
},
?
// 5.驗(yàn)證姓名,可以是中文或英文
name: {
validator: function (value) {
return /^[\Α-\¥]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value);
},
message: '請(qǐng)輸入姓名'
},
// 6.驗(yàn)證用戶名,可以是中文或英文
username: {// 驗(yàn)證用戶名
validator: function (value) {
return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value);
},
message: '用戶名不合法(字母開(kāi)頭,允許6-16字節(jié),允許字母數(shù)字下劃線)'
},
?
// 7.驗(yàn)證日期
date: {// 驗(yàn)證日期
validator: function (value) {
//格式y(tǒng)yyy-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: '清輸入合適的日期格式'
},
?
// 8.驗(yàn)證英語(yǔ)
english: {// 驗(yàn)證英語(yǔ)
validator: function (value) {
return /^[A-Za-z]+$/i.test(value);
},
message: '請(qǐng)輸入英文'
},
//9.國(guó)內(nèi)郵編驗(yàn)證
zipcode: {
validator: function (value) {
var reg = /^[1-9]\d{5}$/;
return reg.test(value);
},
message: '郵編必須是非0開(kāi)始的6位數(shù)字.'
},
// 10.驗(yàn)證身份證
idcard: {// 驗(yàn)證身份證
validator: function (value) {
return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
},
message: '身份證號(hào)碼格式不正確'
},
// 11.驗(yàn)證最小長(zhǎng)度
minLength: {
validator: function (value, param) {
return value.length >= param[0];
},
message: '請(qǐng)輸入至少(2)個(gè)字符.'
},
// 12.驗(yàn)證整數(shù)還是小數(shù)
intOrFloat: {// 驗(yàn)證整數(shù)或小數(shù)
validator: function (value) {
return /^\d+(\.\d+)?$/i.test(value);
},
message: '請(qǐng)輸入數(shù)字,并確保格式正確'
},
// 13.驗(yàn)證QQ
qq: {// 驗(yàn)證QQ,從10000開(kāi)始
validator: function (value) {
return /^[1-9]\d{4,9}$/i.test(value);
},
message: 'QQ號(hào)碼格式不正確'
},
// 14.驗(yàn)證整數(shù) 可正負(fù)數(shù)
integer: {// 驗(yàn)證整數(shù) 可正負(fù)數(shù)
validator: function (value) {
return /^[+]?[1-9]+\d*$/i.test(value);
//return /^([+]?[0-9])|([-]?[0-9])+\d*$/i.test(value);
},
message: '請(qǐng)輸入整數(shù)'
},
// 15.驗(yàn)證年齡
age: {// 驗(yàn)證年齡
validator: function (value) {
return /^(?:[1-9][0-9]?|1[01][0-9]|120)$/i.test(value);
},
message: '年齡必須是0到120之間的整數(shù)'
},
//16.驗(yàn)證是否包含非法字符
unnormal: {// 驗(yàn)證是否包含空格和非法字符
validator: function (value) {
return /.+/i.test(value);
},
message: '輸入值不能為空和包含其他非法字符'
},
//17.驗(yàn)證傳真
faxno: {// 驗(yàn)證傳真
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: '傳真號(hào)碼不正確'
},
//18.驗(yàn)證數(shù)字
number: {
validator: function (value, param) {
return /^[0-9]+.?[0-9]*$/.test(value);
},
message: '請(qǐng)輸入數(shù)字'
},
//19.驗(yàn)證密碼兩次的輸入是否相同
same: {
validator: function (value, param) {
if ($("#" + param[0]).val() != "" && value != "") {
return $("#" + param[0]).val() == value;
} else {
return true;
}
},
message: '兩次輸入的密碼不一致!'
},
//20.驗(yàn)證車牌號(hào)碼
carNo: {
validator : function(value) {
return /^[\u4E00-\u9FA5][\da-zA-Z]{6}$/.test(value);
},
message : '車牌號(hào)碼無(wú)效(例:粵B12350)'
},
//21.用戶賬號(hào)驗(yàn)證(只能包括 _ 數(shù)字 字母)
account: {//param的值為[]中值
validator: function (value, param)
{
if (value.length < param[0] || value.length > param[1])
{
$.fn.validatebox.defaults.rules.account.message = '用戶名長(zhǎng)度必須在' + param[0] + '至' + param[1] + '范圍';
return false;
}
else
{
if (!/^[\w]+$/.test(value))
{
$.fn.validatebox.defaults.rules.account.message = '用戶名只能數(shù)字、字母、下劃線組成.';
return false;
}
else
{
return true;
}
}
},
message: ''
}
});
});
</script>
轉(zhuǎn)載于:https://www.cnblogs.com/Lxiaojiang/p/5928872.html
總結(jié)
以上是生活随笔為你收集整理的easyUI validate函数【总结篇-部分转】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 下 面 这 条 语 句 一 共 创 建
- 下一篇: 图像二维离散傅里叶变换、幅度谱、相位谱