badmfck-api-server 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,13 @@
|
|
1
|
+
export type TValidatorType = "string" | "number" | "boolean" | "date" | "array" | "object" | "email" | "phone";
|
1
2
|
export interface IValidatorOptions {
|
2
3
|
min?: number;
|
3
4
|
max?: number;
|
4
|
-
type?:
|
5
|
+
type?: TValidatorType;
|
5
6
|
regex?: RegExp;
|
6
7
|
}
|
7
8
|
export interface IValidaotrType {
|
8
9
|
name: string;
|
9
|
-
type:
|
10
|
+
type: TValidatorType;
|
10
11
|
optional?: boolean;
|
11
12
|
arrayType?: IValidaotrType;
|
12
13
|
}
|
@@ -86,6 +86,9 @@ class Validator {
|
|
86
86
|
return ValidationReport.VALUE_TOO_BIG;
|
87
87
|
if (opt.min && value.length < opt.min)
|
88
88
|
return ValidationReport.VALUE_TOO_SHORT;
|
89
|
+
if (opt.type === "email" && !opt.regex) {
|
90
|
+
opt.regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g;
|
91
|
+
}
|
89
92
|
if (opt.regex) {
|
90
93
|
const tmp = value.replaceAll(opt.regex, "");
|
91
94
|
if (tmp.length !== 0)
|