email method
Asserts that a string property is a valid email format.
Implementation
PropertyRuleBuilder<T, V> email([String? customMessage]) {
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
_validators.add((val) {
if (val is String && val.isNotEmpty && !emailRegex.hasMatch(val)) {
return customMessage ?? 'Invalid email address.';
}
return null;
});
return this;
}