Dead simple field/object schema validation for flutter
EzValidator api is inspired by Yup
EzValidator is a flutter schema builder for value validation. Define a schema, validate the shape of an existing value, or both. EzValidator allow single or object validations
Add EzValidator to your pubspec:
dependencies:
ez_validator: any # or the latest version on Pub
You define your schema object. check the exemple folder of how to use validation with multiple form with showing errors
EzSchema mySchema = EzSchema.shape({
"email": EzValidator().required().email().build(),
"password": EzValidator()
.required()
.minLength(6)
.matches(
r'^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{6,}$',
'Minimum six characters, at least one letter, one number and one special character')
.build(),
"age": EzValidator().required().min(18).build(),
}, identicalKeys: true);
// check validity
Map<String, String> errors = mySchema.validateSync({
"email": 'iheb@pixelium.tn',
"password": '444',
"age": "17"
});
print(errors);
// output if the form not valid
//
// {
// "password": "Minimum six characters, at least one letter, one number and one special character",
// "age": "The field must be greater than or equal to 18"
// }
//
//
// output if the form is valid
//{}
exemple of using defaultTest
EzSchema mySchema = EzSchema.shape({
.....
"sum": EzValidator()
.required()
.defaultTest(
'Test not valid please recheck', (v) => int.parse(v as String) > 25)
.build(),
....
};
with default locale | with custom locale |
---|---|
Validates if the value is not empty or null.
Validates if the value length is not less than minLength
.
Validates if the value length is not more than maxLength
.
Validates if the value is lesser or equal to min
.
Validates if the value is higher or equal max
.
Validates if the value is positive.
Validates if the value is negative.
Checks if the value is an email address.
Checks if the value is a valid uuid.
Checks if the value is a number.
Checks if the value is boolean (true,false).
Checks if the value is a date type.
Checks if the value is not a number.
Checks if the value is on lowercase.
Checks if the value is on uppercase.
Checks if the value is one of the follwoing items
.
Checks if the value is not one of the follwoing items
.
Checks if the value is a phone number.
Checks if the value is correct IPv4 address.
Checks if the value is correct IPv6 address.
Checks if the value is correct url address.
Validates if the value does matches with the pattern.
Validates the value with your own validation logic
Validator code inspired from form_validator