Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Created September 25, 2019 12:45
Show Gist options
  • Save aslamanver/3a3389b8ef88831128f0fa21393d70f0 to your computer and use it in GitHub Desktop.
Save aslamanver/3a3389b8ef88831128f0fa21393d70f0 to your computer and use it in GitHub Desktop.
Email Validation in Dart
bool 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 regex = new RegExp(pattern);
return (!regex.hasMatch(value)) ? false : true;
}
void main() {
print(validateEmail("aslam@gmail.com"));
}
@kushande
Copy link

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 regex = new RegExp(pattern);

Why using pattern "The argument type 'Pattern' can't be assigned to the parameter type 'String'."

@sethyanita
Copy link

bool 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 regex = new RegExp(pattern);
return (!regex.hasMatch(value)) ? false : true;
}

void main() {
print(validateEmail("aslam@gmail.com"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment