email static method

String? email(
  1. String? value, {
  2. String? message,
})

Validates email format.

Implementation

static String? email(String? value, {String? message}) {
  if (value == null || value.isEmpty) {
    return null;
  }

  final emailRegex = RegExp(
    r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
  );

  if (!emailRegex.hasMatch(value)) {
    return message ?? 'Please enter a valid email address.';
  }

  return null;
}