validateEmail static method
- String? value,
- BuildContext context
Validates an email address to ensure it is not empty, has a valid format, and DHBW domain. @param value The email string to validate. @param context The BuildContext for localization. @return A string error message if validation fails, or null if it passes.
Implementation
*////
/// Validates an email address to ensure it is not empty, has a valid format, and DHBW domain.
/// @param value The email string to validate.
/// @param context The BuildContext for localization.
/// @return A string error message if validation fails, or null if it passes.
static String? validateEmail(String? value, BuildContext context) {
if (value == null || value.isEmpty) return AppLocalizations.of(context)!.tEmailCannotEmpty;
if (!GetUtils.isEmail(value)) return AppLocalizations.of(context)!.tInvalidEmailFormat;
// TODO: Uncomment this line to restrict email domains after development phase
//if (!RegExp(r'^[\w\.-]+@[\w\.-]*dhbw[\w\.-]*\.de$').hasMatch(value)) return tOnlyDHBWEmailAllowed;
return null;
}