-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
crossjs
committed
May 16, 2014
1 parent
b5b9490
commit fc21eb2
Showing
4 changed files
with
147 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define({ | ||
'required': '此项必填', | ||
// TODO: 从title中获取 | ||
'pattern': '不符合规则', | ||
'minlength': '请输入至少{0}个字符', | ||
'maxlength': '最多输入{0}个字符', | ||
'min': '不能小于{0}', | ||
'max': '不能大于{0}', | ||
'equalto': '两次输入的内容不一致,请重新输入', | ||
'minto': '不能小于{0}', | ||
'maxto': '不能大于{0}', | ||
// 'password': '密码只能包含ASCII字符', | ||
'digits': '请输入数字', | ||
'number': '请输入数字', | ||
'url': '请输入URL地址', | ||
'async': '异步校验失败,请检查' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
define({ | ||
required: function (params) { | ||
var elem = params.elem; | ||
// 如果是单复选框,则特殊判断 | ||
if (/radio|checkbox/.test(elem.prop('type'))) { | ||
if (params.name) { | ||
return !!this.$('[name="' + params.name + '"]:checked').length; | ||
} | ||
return elem.is('input[type="checkbox"]'); | ||
} | ||
return (/\S/).test(params.value); | ||
}, | ||
pattern: function (params) { | ||
return new RegExp(params.prop).test(params.value); | ||
}, | ||
minlength: function (params) { | ||
var len = params.value.length; | ||
return len ? (len >= params.prop) : true; | ||
}, | ||
maxlength: function (params) { | ||
var len = params.value.length; | ||
return len ? (len <= params.prop) : true; | ||
}, | ||
min: function (params) { | ||
return parseInt(params.value, 10) >= params.prop; | ||
}, | ||
max: function (params) { | ||
return parseInt(params.value, 10) <= params.prop; | ||
}, | ||
equalto: function (params) { | ||
return params.value === this.$('[name="' + params.prop + '"]').val(); | ||
}, | ||
minto: function (params) { | ||
return parseInt(params.value, 10) >= parseInt(this.$('[name="' + params.prop + '"]').val(), 10); | ||
}, | ||
maxto: function (params) { | ||
return parseInt(params.value, 10) <= parseInt(this.$('[name="' + params.prop + '"]').val(), 10); | ||
}, | ||
digits: function (params) { | ||
return !/\D/.test(params.value); | ||
}, | ||
number: function (params) { | ||
return !isNaN(params.value); | ||
}, | ||
url: function (params) { | ||
return (/^(https?:)?\/\/([\w\d][\w\d\-]*(\.[\w\d][\w\d\-]*)*(\.\w{2,})+)(\/\S*)?$/i).test(params.value); | ||
}, | ||
// 异步验证,如:从服务端验证、校验动态加载的图片尺寸 | ||
async: function (params) { | ||
this.pendingCount++; | ||
|
||
params.prop.call(this, function (success) { | ||
if (success) { | ||
this.pendingCount--; | ||
} else { | ||
this.addError(params); | ||
} | ||
// 检查 | ||
this.checkValidation(); | ||
}); | ||
|
||
return 'pending'; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters