-
-
Save aslamanver/3a3389b8ef88831128f0fa21393d70f0 to your computer and use it in GitHub Desktop.
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("[email protected]")); | |
} |
Why don't you do this? Any reason?
return (!regex.hasMatch(value)) ? false : true;
=>
return regex.hasMatch(this);
That's also one of the ways.
@aslamanver
yes, it is. perhaps, the negative check syntax is faster than the positive check in the computer science?
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'."
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("[email protected]"));
}
Why don't you do this? Any reason?
return (!regex.hasMatch(value)) ? false : true;
=>
return regex.hasMatch(this);