xxxxxxxxxx
import 'package:flutter/material.dart';
bool validateEmail(String email) {
// Regular expression pattern to match an email address
Pattern pattern = r'^[\w-]+(\.[\w-]+)*@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$';
RegExp regExp = new RegExp(pattern);
return regExp.hasMatch(email);
}
void main() {
String email = "test@example.com";
if (validateEmail(email)) {
print("Email is valid");
} else {
print("Email is not valid");
}
}
xxxxxxxxxx
String validateEmail(String value) {
Pattern pattern =
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]"
r"{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]"
r"{0,253}[a-zA-Z0-9])?)*$";
RegExp regex = new RegExp(pattern);
if (!regex.hasMatch(value) || value == null)
return 'Enter a valid email address';
else
return null;
}
xxxxxxxxxx
if (value!.isEmpty) {
return "Please enter your Email";
}
if (!RegExp(
r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$')
.hasMatch(value)) {
print("email is true");
return 'Please enter a valid email';
}
return null;
xxxxxxxxxx
var email = "tony@starkindustries.com"
bool emailValid = RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email);