Flutter: How to specify exact character to appear during email validation
1,174
It can check domains like [email protected]
and [email protected]
void main() {
var email = "[email protected]";
bool emailValid = RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$').hasMatch(email);
print (emailValid); // true
}
Author by
Shadow Walker
Updated on December 25, 2022Comments
-
Shadow Walker over 1 year
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");
-
Alexander Mashin over 3 yearsAnd 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@
. -
Shadow Walker over 3 years@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.
-