简体   繁体   English

当前验证表单中电子邮件地址的最佳实践是什么?

[英]What are the current best practices for validating email addresses in forms?

I know there are some complicated regular expressions that can help with this, but I'm wondering if this approach is even being used these days? 我知道可以使用一些复杂的正则表达式来解决这个问题,但是我想知道这些天是否还在使用这种方法?

My particular question has to do with a "Get a Quote" form on a website I'm building. 我的特定问题与正在建立的网站上的“获取报价”表格有关。 Sending a validation email to the user requiring a response might not be appropriate since no accounts are being set up. 由于没有设置任何帐户,因此不适合向用户发送确认电子邮件以要求响应。 But are regular expressions the way to go? 但是正则表达式是走的路吗? I'm just wondering what's being done about this these days. 我只是想知道这几天正在做什么。

Using regexes for validating emails is quite useless. 使用正则表达式来验证电子邮件是完全没有用的。

They don't catch typos in email addresses. 他们不会在电子邮件地址中发现拼写错误。 Use email verification form field for this. 为此,请使用电子邮件验证表单字段。

They don't ensure that syntactically valid email address actually exists. 他们不确保语法上有效的电子邮件地址确实存在。 If you want the email address to be able to send them some mails, then this is what you have to do, send the verification email with a link. 如果您希望该电子邮件地址能够向他们发送一些邮件,那么您要做的就是发送带有链接的验证电子邮件。 If you don't want to send them emails, then, from your perspective, there's no difference between "foobar1234" and "12856723984562983456283456@example.com". 如果您不想向他们发送电子邮件,那么从您的角度来看,“ foobar1234”和“ 12856723984562983456283456@example.com”之间没有区别。

And besides, unless you go full RFC on this, there will be some pissed off users with "strange" emails which your regex rejected. 此外,除非您对此进行完整的RFC审查,否则有些用户会因为“正则”电子邮件而生气,而您的正则表达式拒绝了该电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM