Skip to main content

validateEmail method

String? validateEmail (String email)

Implementation

static String? validateEmail(
String email,
) \{
If email is empty return.
if (email.isEmpty) \{
return "Email must not be left blank";
\}
const String pattern =
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`\{|\}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]\{0,253\}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]\{0,253\}[a-zA-Z0-9])?)*$";
final RegExp regex = RegExp(pattern);
if (!regex.hasMatch(email)) \{
return 'Please enter a valid Email Address';
\}
return null;
\}