Skip to content

Email validation with german umlauts #13215

Closed
@martin-skroch

Description

@martin-skroch

I have the problem that the email validation fails if I use an email with german umlauts.

I know, laravel use the filter_var function of php with the filter FILTER_VALIDATE_EMAIL, but this is outdated, because there are so-called IDNs (Internationalized domain names) which are not considered in this filter.

Now we can wait until php reworked it or we can implement an alternative respectively a small solution to convert the domain of an emal to ascii with idn_to_ascii(). The only drawback is that this function requires the intl extension for php.

Here, I have found a solution which works for me. I have implemented a Custom Validation Rules like so:

Validator::extend('idn_email', function($attribute, $value, $parameters, $validator) {
    $valueParts = explode('@', $value);
    return count($valueParts) == 2 && filter_var($valueParts[0].'@'.idn_to_ascii($valueParts[1]), FILTER_VALIDATE_EMAIL) !== false;
});

This solution only convert the domain name from idn in ascii and then we can use the filter_var again.

I think it is a clean solution. What do you say?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions