validator.js
validator.js copied to clipboard
feat(isEmail): added allowed_wildcard option for isEmail validator
The isEmail validator uses the isFQDN validator, which has the option allowed_wildcard.
For a project I need to validate an email with a wildcard. I simply add the allowed_wildcard option to the isEmail validator so that it can pass the option to the isFQDN validator.
Checklist
- [x] PR contains only changes related; no stray files, etc.
- [x] README updated (where applicable)
- [x] Tests written (where applicable)
- [ ] References provided in PR (where applicable)
I think this would break the meaning of isEmail validator. For wildcard validation, pattern matching would be more feasible than using it on isEmail.
@rubiin Do you have an example of how to use filtering?
To give you a bit more context, for my business case I'd like to validate an email field that can also have emails with wildcards, which is why I came up with this proposal.
For the moment, what I've found on my side is to do a 2-step validation. I use the isFQDN method to validate the domain of my email, then I remove the wildcard to validate my email with the isEmail method. But I don't find this very fun to do.
If you have a simpler idea, I'd love to hear it.
I agree with @rubiin, isEmail should only validate valid emails. Your 2-step validation seems like a reasonable workaround to me.