mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-06 15:34:06 +08:00
added one more validation function
This commit is contained in:
parent
e7c93f7620
commit
025c20268a
1 changed files with 19 additions and 0 deletions
|
|
@ -91,5 +91,24 @@ module.exports = {
|
|||
}
|
||||
});
|
||||
return true;
|
||||
},
|
||||
validateObjectValues(val){
|
||||
let errCount = 0;
|
||||
if (val === null || val === undefined) {
|
||||
//
|
||||
} else if (Array.isArray(val)) {
|
||||
//array
|
||||
val.forEach((val2) => {
|
||||
errCount += validateObjectValues(val2);
|
||||
});
|
||||
} else if (typeof val === "object" && !Array.isArray(val)) {
|
||||
//object
|
||||
Object.keys(val).forEach((valkey) => {
|
||||
errCount += validateObjectValues(val[valkey]);
|
||||
});
|
||||
} else {
|
||||
if (!/^[0-9a-zA-Z._\-\+]+$/.test(val)) errCount++;
|
||||
}
|
||||
return errCount == 0;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue