Skip to content

Instantly share code, notes, and snippets.

@rapPayne
Created October 21, 2020 21:25
Show Gist options
  • Select an option

  • Save rapPayne/374097359bc3a13e4e1529d22dbe409a to your computer and use it in GitHub Desktop.

Select an option

Save rapPayne/374097359bc3a13e4e1529d22dbe409a to your computer and use it in GitHub Desktop.
Validating a Simple TextFormField
String _validateEmail(String email) {
// 1
RegExp regex = RegExp(r'\w+@\w+\.\w+'); // translates to word@word.word
// 2
if (email.isEmpty)
return 'We need an email address';
else if (!regex.hasMatch(email))
// 3
return "That doesn't look like an email address";
else
// 4
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment