Validate email address in Dart?

Eric Lavoie picture Eric Lavoie · May 28, 2013 · Viewed 70.2k times · Source

According to RegExp documentation, we must use JavaScript (Perl 5) regular expressions : ECMA Specification. What pattern do you use for email validation in Dart? Is there any different way than JavaScript to achieve this in Dart?

Answer

Airon Tark picture Airon Tark · Jun 3, 2018

For that simple regex works pretty good.

var email = "[email protected]"
bool emailValid = RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email);