Now you can use ValidationBuilder class to create validation logic. Here's simple validator that validates if input length is between 10 and 50 characters long.
final validate = ValidationBuilder().minLength(10).maxLength(50).build();
print(validate('test')); // Minimum length must be at least 10 charactersprint(validate('Hello World')); // null, means value is correct
Localization
You can set global locale using ValidationBuilder.setLocale(String localeName)
or you can also define locale on ValidationBuilder({ String localeName }) constructor.
ValidationBuilder.setLocale('en');
// will use *en* localizationValidationBuilder()
.minLength(5)
.build();
// will use *az* localizationValidationBuilder(localeName: 'az')
.minLength(5)
.build();
// will display custom messageValidationBuilder()
.minLength(5, 'Length < 5 😟')
.build();
Methods
.minLength(int minLength, [String message])
Validates if value length is not less than minLength.
.maxLength(int maxLength, [String message])
Validates if value length is not more than maxLength.
.email([String message])
Checks if value is an email address.
.phone([String message])
Checks if value is an phone number.
Note: This method might be changed in future.
.ip([String message])
Checks if value is correct IPv4 address.
.ipv6([String message])
Checks if value is correct IPv6 address.
.url([String message])
Checks if value is correct url address.
.match(String otherValue, [String message])
Checks if the value matches the specified otherValue. This can be used to validate if two input values are identical.
Validates if value passes any of left and right validations. If value doesn't passes any error message from right validation will be displayed (If reverse set to true message from left validation will be displayed).