fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.32k stars 204 forks source link

feat: add rfc5322 validator #912

Open hendrikheil opened 2 weeks ago

hendrikheil commented 2 weeks ago

This PR implements a new action for RFC 5322 based email address validation. A few things are of particular importance.

  1. The regex used in this PR was taken from the HTML living standard and has a few willful violations of RFC 5322
  2. It is impossible and unrealistic to parse a fully RFC compliant email address with a regular expression, as the spec allows for comments, which are made of balanced potentially nested parenthesis pairs. However, email clients such as Gmail don't accept these addresses either
  3. If the willful violations are not acceptable, it is likely that parsing an address without a regex is a better choice.

I opted to reuse the types, reference and type of the default email action so that there is just a single case for i18n messages. I'm not sure if that approach is ideal, but I'd be happy to change it. I'll add documentation after this question is answered as not to duplicate the work.

Fix #204

fabian-hiller commented 2 weeks ago

Thank you for creating this PR! I would not reuse email and create a brand new action instead, as I think this makes the library simpler. We have never reused an action in this way.