Allow Norwegian and special letters when checking email

When using the following PHP to check email, is there a way to allow Scandinavian vowels such as Æ, Ø and Å?

if(!filter_var($email,FILTER_VALIDATE_EMAIL)==false)

They are rarely used in domains, but sometimes it would be useful to have functionality.

+4
source share
1 answer

Just replace them with valid characters and confirm them as shown in your question.

For example (replacing all the characters from (Æ, Ø, Å with a):

DÆVEØ@Ådomain.com -> DaVEa@adomain.com -> valid

While:

DÆVE -> DaVE -> invalid

An example :

<?php

$email = 'DÆVEØ@Ådomain.com';
$email_check = str_replace(['Æ', 'Ø', 'Å'], 'a', $email);

echo $email . ' is ';
var_dump(!filter_var($email_check, FILTER_VALIDATE_EMAIL) === false);


$email = 'DÆVE';
$email_check = str_replace(['Æ', 'Ø', 'Å'], 'a', $email);

echo $email . ' is ';
var_dump(!filter_var($email_check, FILTER_VALIDATE_EMAIL) === false);

Output:

DÆVEØ@Ådomain.com is bool(true)
DÆVE is bool(false)
+4
source

Source: https://habr.com/ru/post/1535194/


All Articles