Skip to content

Instantly share code, notes, and snippets.

@loonix
Last active March 23, 2021 15:42
Show Gist options
  • Save loonix/10b88ea28afe568d0c19e3f1346c76ca to your computer and use it in GitHub Desktop.
Save loonix/10b88ea28afe568d0c19e3f1346c76ca to your computer and use it in GitHub Desktop.
[Dart Email Regex]
/// Needed to make a regex that matched my criterias, there are a few regex already made that do not take into acount domais that end in .services
/// for international email please have a look at this regex https://rubular.com/r/bqNZ0WT0RMSaGV
main() async {
_checkEmail("a@a"); // false
_checkEmail("a@a.a"); // false
_checkEmail("s@asd,com"); // false
_checkEmail("a@aa.co,uk"); // false
_checkEmail("a@a.aa"); // true
_checkEmail("a@aa.aa"); // true
_checkEmail("aa@aa.aa.aa"); // true
_checkEmail("aa.aa@aa.aa.aaaaaaaaa"); // true
_checkEmail("aaaaaaaa-aaaaaaaaa.aaaaaaa@aaaaa-aaaaaa.aaaaaaa.aaaaaaaaa"); // true
}
/// in case you need the email regex to support international emails replace the regexp with
/// RegExp(r'^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');
_checkEmail(email){
bool emailValid = RegExp(r"^(?=^.{6,255}$)([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,85}$").hasMatch(email);
print("${email.toString()} - ${emailValid.toString()}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment