isMail method Null safety

bool? isMail()

Checks whether the String is a valid mail.

Example

String foo = 'esentis@esentis.com';
bool isMail = foo.isMail(); // returns true

Implementation

bool? isMail() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return false;
  }
  var regex = RegExp(r"(^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$)");
  return regex.hasMatch(this!);
}