Respect / Validation

The most awesome validation engine ever created for PHP
https://respect-validation.readthedocs.io
MIT License
5.75k stars 774 forks source link

Email validation with accented characters #1458

Closed thierryler closed 1 month ago

thierryler commented 1 month ago

Hello,

For some reasons, my email client can not send emails to addresses with accented characters. Therefore, I'd like to check emails.

I wrote:

$email = 'sébastien@company.com";
if(!v::notEmpty()->validate($email)) {
  // send error (empty)
} else if(!v::email()->validate($email)) {
  // send error (invalid)
} else {
  // OK
}

Here v::email()->validate($email) does not fail. And it is OK.

But i'd like to add a condition like this:

} else if(!v::onlyStandardChars()->validate($email)) {
  // send error (accents)
}

What would be the best way? Is v::charset('ASCII')a good idea?

Thx Th

andus4n commented 1 month ago

v::alnum('@', '.')->email()->validate($email); you could also add stringType + length (i always do).

henriquemoody commented 1 month ago

Thanks for reacting to the issues, @andus4n!

If your go for that solution, @thierryler, you will also need to add other characters, like _ and -, which are also common in emails. The v::charset('ASCII') is also a good option. However, all those are error prone, though. The best solution would be to indeed have an email client that would allow those emails, since they're valid.

I will close this one now, it seems there isn't anything else to do! Feel free to open this issue whenever you'd like.

thierryler commented 1 month ago

Actually, I plain to move from swift mailer (on my linux server) to Brevo(by API). I will then try again.