From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Validate email address with accented characters

Validate email address with accented characters

From the course: PHP Tips, Tricks, and Techniques

Validate email address with accented characters

- [David] Hi, I'm David Powers and welcome to this week's edition of PHP Tips, Tricks, and Techniques designed to help you become a smarter, more productive PHP developer. This week's tip is gonna be short but, I hope, sweet. This particular problem popped up a couple of years ago in a forum I help moderate. The Swedish developer was having difficulty validating email addresses that contained exempted characters. Now, even if you work exclusively in English, I think this tip could come in useful. Trying to create a regular expression to match a valid email address is notoriously difficult, so he was using the built-in PHP filter_var function with the FILTER_VALIDATE_EMAIL constant. It worked fine with unaccented characters but the local part of an email address, in other words, this part, just before the @ mark, can contain not only accented characters but also characters from other alphabets, like this one, here, which is in Cyrillic. Now, in this example file, I've created an array…

Contents