Validation

Validate field with required
1
2
3
4
5
6
7
    _id: EType.objectId,
    firstName: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            required: true
        }
    }
Validate field with min
1
2
3
4
5
6
    pincode: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            min: 6
        }
    }
Validate field with max
1
2
3
4
5
6
    salary: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            max: 9
        }
    }
Validate field with minLength
1
2
3
4
5
6
    firstName: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            minLength: 3
        }
    }
Validate field with maxLength
1
2
3
4
5
6
    firstName: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            maxLength: 15
        }
    }
Validate field with unique
1
2
3
4
5
6
    firstName: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            unique: true
        }
    }
Validate field with email
1
2
3
4
5
6
    mailId: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            email: true
        }
    }
Validate field with validatorFun
    country_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            validatorFun: <any><IFunctionJSON> {
                hash: '12345645616148',
                code: `(str) => {
                   if (str && ['AHMEDABAD', 'SURAT'].includes(str)) throw new Error("You can not save country_name as '"+ str+ "'");
                   else return true;
                }`,
           }
        }
    }
Multiple validation in single field
1
2
3
4
5
6
7
8
9
    _id: EType.objectId,
    first_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            required: true,
            minLength: 3,
            maxLength: 15
        }
    }
All in one
    _id: EType.objectId,
    first_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            required: true
        }
    },
    area_pincode: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            min: 6
        }
    },
    monthly_salary: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            max: 9
        }
    },
    last_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            minLength: 3
        }
    },
    last_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            maxLength: 15
        }
    },
    mobile_no: <ISchemaProperty>{
        __type: EType.number,
        validations: <IPropertyValidation>{
            unique: true
        }
    },
    mail_Id: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            email: true
        }
    },
    country_name: <ISchemaProperty>{
        __type: EType.string,
        validations: <IPropertyValidation>{
            validatorFun: <any><IFunctionJSON> {
                hash: '12345645616148',
                code: `(str) => {
                   if (str && ['AHMEDABAD', 'SURAT'].includes(str)) throw new Error("You can not save country_name as '"+ str+ "'");
                   else return true;
                }`,
           }
        }
    }