ealush / vest

Vest ✅ Declarative validations framework

Home Page:https://vestjs.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No email validation

martygo opened this issue · comments

A regex could be created to take care of email validation in the most common scenarios.

By the way, how can I contribute to the project, in addition to reporting issues?

Thanks.

Hey @martygo! Thank you for reaching out.

Vest intentionally does not include some built in validations, email is one of them.

Even though these all have strict specs, I learned the hard way that they are more of business decisions that technical matters. What is a valid email? Well, there's a clear spec - but not all companies want the whole spec.
For example, the spec allows for brackets, and + aliases. I've worked at places that do not allow these, and some that allow aliases only for employees. Vest can't assume these decisions for you.

Making any sort of decision on these matters from Vest's side means leaving some cases unhandled, or even worse - adding more configuration and bloat that people won't need.

The compromise is simple. Vest supports extending the built-in enforcements by using enforce.extend. One of the most recommended ways of adding custom email validations is using the excellent validator package for adding those business specific validations.

https://vestjs.dev/#/./n4s/external?id=consuming-external-rules

import isEmail from 'validator/es/lib/isEmail';

enforce.extend({ isEmail });

enforce('example@example.com').isEmail(); // ✅
enforce('example[at]example[dot]com').isEmail(); // 🚨

--

Regarding project support, there are quite a few things possible at the moment, but most opportunities will open up soon.
I am working on the fourth major version of Vest which will introduce some internal changes, and following the release I will open up more issues. At the moment I try not to add new issues to not introduce conflicting changes.

Some things that do can be done in the meantime:

  • Improving test coverage
  • Adding a reactive interface to Vest, possibly a wrapper.
  • Improving the overall documentation.

If any of these interests you, let's talk :)

Thanks!