-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add email
validator
#39
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add the email validator, I think we just forgot to port it over.
Parity with implementation of reactive form email validator?
Though this library makes its own assumptions on validation among other things, I noticed as I lifted the regex pattern that reactive forms email validator explicitly says: // don't validate empty values to allow optional controls
However, other validators in this library, especially pattern as a close reference, does validate against null and undefined. And for the moment, I have made this library's proposed email validator do the same.
Tests?
Great catch, I think we should try to keep as close to possible to the Angular behavior. Feel free to update the validator to also accept empty strings.
For the tests, see my comment in the referenced issue.
|
||
export function email(): ValidatorFn { | ||
return (value: unknown, setState: SetValidationState) => { | ||
const valid = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about invoking the regexp validator with the email regexp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make a lot more sense lol
I could do that. However, I think if this is done, then it should be done for a few other validators as well. As per that file I link from their implementation, the same "don't validate empty values to allow optional controls" is done for: Angular's validators names
This library has all of these as well and it looks like the equivalents also could use updating Should they all be updated? |
The ones that accept a string as value should be updated imho.
|
Work in progress, would this be considered for acceptance
Reasoning
pattern
, I would probably throw the exact same regex string at it every time. I have added many email validators across various apps in my experience, so in my opinion this convenience of having a premadeemail
validator outweighs the potential redundance.Outstanding work
email
validator?email
validator explicitly says:// don't validate empty values to allow optional controls
pattern
as a close reference, does validate againstnull
andundefined
. And for the moment, I have made this library's proposedemail
validator do the same.