email static method

String? email(
  1. String? value
)

Validates if the input is a valid email address.

Implementation

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

  // More comprehensive email regex
  final emailRegex = RegExp(
    r'^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$',
  );

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

  // Additional checks for common issues
  if (value.contains('..')) return 'Email contains consecutive dots';
  if (value.startsWith('.') || value.endsWith('.')) {
    return 'Email cannot start or end with a dot';
  }

  return null;
}