Skip to content

Instantly share code, notes, and snippets.

@gireesh092
Created April 6, 2019 12:20
Show Gist options
  • Save gireesh092/46f1b0862e5d20c64b7b6395a923fdef to your computer and use it in GitHub Desktop.
Save gireesh092/46f1b0862e5d20c64b7b6395a923fdef to your computer and use it in GitHub Desktop.
flutter email validation
String _validateEmail(String value) {
Pattern pattern =
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,}))$';
RegExp regExp = new RegExp(pattern);
if (value.isEmpty) {
return "Please enter an E-Mail ID.";
} else if (!regExp.hasMatch(value)) {
return "Invalid E-Mail address.";
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment