validateEmail static method
Validates an email address.
Returns null if valid, or an error message if invalid.
email The email to validate. Can be null.
Implementation
static String? validateEmail(String? email) {
if (email == null || email.isEmpty) {
return 'Email is required';
}
// Basic email validation regex
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
if (!emailRegex.hasMatch(email)) {
return 'Please enter a valid email address';
}
return null;
}