2

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");
Shadow Walker
  • 979
  • 5
  • 27
  • 51
  • 1
    And then we will struggle for hours trying to fill out some web form, because someone thinks that email can be only in second-level domain in `.com` zone, and without hyphens or underscores before `@`. – Alexander Mashin Oct 16 '20 at 07:46
  • @AlexanderMashin i know about adding hyphens or underscores but i don't need it for what i want to achieve. There is a reason i want it to appear that way. Don't try to think for me. – Shadow Walker Oct 16 '20 at 07:51

1 Answers1

3

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
}
Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147