FieldValidator class

A utility class providing common field validators.

The FieldValidator class contains static methods for common validation tasks, such as checking if a field is required, validating the length of a string, or ensuring a field is a number or an email address.

Constructors

FieldValidator.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

checkByRegexp(RegExp pattern, {bool isRequired = true}) ValidatorEvent
Validator to check if a field matches a given regular expression pattern. The validator checks whether the provided value matches the specified regex pattern. If the value does not match the pattern, an error message 'error.field.regex' is returned. Parameters:
contains(List values, {bool isRequired = true}) ValidatorEvent
fieldLength({int? max, int? min}) ValidatorEvent
Validator to check if a field's length falls within a specified range.
hasRelation({required DBCollectionFree collectionModel, String relationField = '_id', bool isRequired = true}) ValidatorEvent
hasSqlRelation({required MySQLConnection db, required String table, required String field, QO operator = QO.EQ, Where? where}) ValidatorEvent
Validator to check if a field value has a relation in a SQL database table. The validator checks whether the provided value exists in the specified table and field. If the value does not exist, an error message 'error.field.relation' is returned. Parameters:
isColorField() ValidatorEvent
Validator to check if a field contains a valid color code. The color code must be a valid hexadecimal color code. The validator checks whether the provided value is non-null, is a non-empty string, and matches the format of a color code. If the validation fails, an error message 'error.field.color' is returned.
isDateField({bool isRequired = true, bool checkUtc = false}) ValidatorEvent
isEmailField() ValidatorEvent
Validator to check if a field contains a valid email address.
isNumberDoubleField({double? max, double? min, bool isRequired = false}) ValidatorEvent
Validator to check if a field is a valid number within optional bounds.
isNumberField({int? max, int? min, bool isRequired = false}) ValidatorEvent
Validator to check if a field is a valid number within optional bounds.
isPasswordField() ValidatorEvent
Validator to check if a field contains a valid password. The password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one number, and one special character. The validator checks whether the provided value is non-null, is a non-empty string, and matches the format of a password. If the validation fails, an error message 'error.field.password' is returned.
isSelectField(List options) ValidatorEvent
Validator to check if a field contains a valid select field. The select field must be a valid value from the list of options. The validator checks whether the provided value is non-null, is a non-empty string, and matches the format of a select field. If the validation fails, an error message 'error.field.select' is returned.
isUniqueSQLField({required MySQLConnection db, required String table, required String field, QO operator = QO.EQ, Where? where}) ValidatorEvent
Validator to check if a field value is unique in a SQL database table. The validator checks whether the provided value already exists in the specified table and field. If the value exists, an error message 'error.field.unique' is returned. Parameters:
requiredField() ValidatorEvent
Validator to check if a field is required (non-null and non-empty).
requiredFieldMultiLanguage() ValidatorEvent
Validator to check if a field is required in multiple languages.