isEmail function

String? isEmail(
  1. String field,
  2. Object? value
)

The string value must be a valid email address.

Implementation

String? isEmail(String field, Object? value) {
  if (value == null || value is! String) return null;
  final regex = RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$');
  return regex.hasMatch(value) ? null : '$field must be a valid email';
}