non-latin email address validation

让人想犯罪 __ 提交于 2019-11-30 12:22:59
Pekka 웃

I think the ultimately best way would be using a proper IDN function to convert the incoming string into an ACE string (xn--xyz-blah.com). If that process works, the domain name is valid. If it doesn't, it isn't.

There is a PHP function named idn_to_ascii() that does this, but it needs additional libraries. You'd have to see whether it is available on your system.

There also seems to be an external Linux command named idn that does IDN conversions. I don't know anything further about it, though.

If you want to use PHP built-in methods only, delfuego provides a regular expression in this question that looks very good.

John Conde

I was going to recommend using filter_var() with the FILTER_VALIDATE_EMAIL filter. But after a Google search it turns out it doesn't support multi-byte characters yet. It looks like, for now, your best bet is to strip out non-latin characters and perform the usual validations against that (although checkdnsrr will obviously fail since you've changed the domain by removing the non-Latin characters and replaced them with their Latin equivalents so if you use that to verify the MX records of the email's domain then you will need to temporarily disable that).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!