mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
This commit is contained in:
parent
039213cf50
commit
55256ada95
23 changed files with 409 additions and 110 deletions
61
app/Lib/Utilities/Validate.js
Normal file
61
app/Lib/Utilities/Validate.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
define([
|
||||
],
|
||||
|
||||
function () {
|
||||
|
||||
function validate(object, description) {
|
||||
|
||||
if(description.optional && (object === null || object === "")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(object === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(typeof object === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(typeof object === 'NaN') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.type == 'array' && !(object instanceof Array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.type != 'array' && typeof object != description.type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.max && object > description.max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.min && object < description.min) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.maxLength && object.length > description.maxLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.minLength && object.length < description.minLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.in && description.in.indexOf(object) === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(description.regex && !description.regex.test(object)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return validate;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue