email static method

String? email(
  1. String? value
)

Validates that the given value is a valid email address.

It checks for a basic email pattern.

Implementation

static String? email(String? value) {
  if (value == null || value.trim().isEmpty) {
    return 'Email is required';
  }

  final regex = RegExp(r'^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$');

  if (!regex.hasMatch(value.trim())) {
    return 'Enter a valid email address';
  }

  return null;
}