PHP 电子邮件验证
对于PHP,使用preg的最佳电子邮件验证是什么,不ereg,因为它已弃用/删除< /强>。
我不需要检查该网站是否存在(这不像最高安全性)。
我发现了很多使用 ereg 的方法,但它们(显然)不是好的做法。
For PHP what is the best email validation using preg, NOT ereg because it's deprecated/removed.
I don't need to check if the website exists (it's not like maximum security).
I've found many ways with ereg but they (obviously) aren't good practice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您使用
FILTER_VALIDATE_EMAIL
过滤器:您还可以使用 其正则表达式:
但在这种情况下,如果在正则表达式中发现错误,则必须更新程序而不仅仅是更新 PHP。
I suggest you use the
FILTER_VALIDATE_EMAIL
filter:You can also use its regular expression directly:
But in that case, if a bug is found in the regular expression, you'll have to update your program instead of just updating PHP.
除非你想使用非常非常长的正则表达式会遇到未涵盖的有效电子邮件地址(想想 Unicode)。此外,虚假电子邮件地址也会被视为有效,因此如果您可以简单地编写 ,那么验证的意义何在? [电子邮件受保护] 并逃脱惩罚?
验证电子邮件地址的最佳方法是发送一封带有点击链接的确认电子邮件。仅当电子邮件地址有效时,这才有效:简单,无需使用正则表达式。
Unless you want to use a very very long regular expressions you'll run into valid email addresses that are not covered (think Unicode). Also fake email addresses will pass as valid, so what is the point of validating if you can simply write [email protected] and get away with it?
The best way to validate email addresses is to send a confirmation email with a link to click. This will only work if the email address is valid: easy, and no need to use regex.
在 if() 条件下调用它,如下例所示:
Call it in if() condition as below example :