Created
September 25, 2019 12:45
-
-
Save aslamanver/3a3389b8ef88831128f0fa21393d70f0 to your computer and use it in GitHub Desktop.
Email Validation in Dart
This file contains 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
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")); | |
} |
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
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'."