Skip to content

Instantly share code, notes, and snippets.

@AlexVegner
Last active March 15, 2021 11:40
Show Gist options
  • Save AlexVegner/95bddb992ab27a3c5f298ff8d0b97b29 to your computer and use it in GitHub Desktop.
Save AlexVegner/95bddb992ab27a3c5f298ff8d0b97b29 to your computer and use it in GitHub Desktop.
rfc 5322 official standard email regex
// The Official Standard: RFC 5322
final emailRegexp = RegExp(
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$");
void main() {
[
'alex.v@gmail.com',
'v@gmail.com',
'v@3.gmail.com',
'@3.gmail.com',
'3.gmail.com',
'v@',
].forEach(checkEmail);
}
checkEmail(String email) {
final checkSimbol = emailRegexp.hasMatch(email) ? '\u{2705}' : '\u{274C}';
print('$checkSimbol - $email');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment