validateEmail static method
Validate given email address
value
: email address
Implementation
static String? validateEmail(String? value) {
const pattern =
r'^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)';
final RegExp regex = RegExp(pattern);
if (value != null && value.isNotEmpty && regex.hasMatch(value)) {
return null;
} else if (value == null || value.isEmpty) {
return 'This filed is required';
} else {
return 'Please enter valid email';
}
}