Flutter: How to specify exact character to appear during email validation

Viewed 1568

In my email validation, I want to make it mandatory that the user should use the full .com extension in there email field. Currently, the way I have my RegExp it only accepts starting with .c or .o or .m instead of throwing an error if there in no exact match with .com

How do I go about resolving this?

Here is my RegExp

final RegExp emailValidatorRegExp = RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+.com");
1 Answers

It can check domains like anything@string.com and anything@string.co.in

void main() {
  var email = "jitsm555@gmail.com";
  bool emailValid = RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$').hasMatch(email);
  print (emailValid); // true
}
Related