isValidEmail method
isValidEmail(string regex): checks if the string is a valid email address
regex: optional parameter, if not specified, the default regex is used
default regex: r'^\w-+(.\w-+)@a-zA-Z\d-+(.a-zA-Z\d-+).a-zA-Z{2,}$'
Implementation
bool isValidEmail({String? regex}) {
if (regex.isNull) {
regex =
r'^[\w-]+(\.[\w-]+)*@[a-zA-Z\d-]+(\.[a-zA-Z\d-]+)*\.[a-zA-Z]{2,}$';
}
return isNull ? false : RegExp(regex!).hasMatch(this!);
}