Skip to content

Instantly share code, notes, and snippets.

@boeledi
Last active March 27, 2023 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boeledi/d1bdc8ca236a9521b6a10fdb96595ee4 to your computer and use it in GitHub Desktop.
Save boeledi/d1bdc8ca236a9521b6a10fdb96595ee4 to your computer and use it in GitHub Desktop.
const String _kEmailRule = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";
class EmailValidator {
final StreamTransformer<String,String> validateEmail =
StreamTransformer<String,String>.fromHandlers(handleData: (email, sink){
final RegExp emailExp = RegExp(_kEmailRule);
if (!emailExp.hasMatch(email) || email.isEmpty){
sink.addError('Entre a valid email');
} else {
sink.add(email);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment