Created
October 21, 2020 21:25
-
-
Save rapPayne/374097359bc3a13e4e1529d22dbe409a to your computer and use it in GitHub Desktop.
Validating a Simple TextFormField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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