1<?php
2$email_a = 'joe@example.com';
3$email_b = 'bogus';
4
5if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
6 echo "L'adresse email '$email_a' est considérée comme valide.";
7}
8if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
9 echo "L'adresse email '$email_b' est considérée comme valide.";
10} else {
11 echo "L'adresse email '$email_b' est considérée comme invalide.";
12}
13?>
1<?php
2 $email = "pattrick@tutorialspoint.com";
3 // Validate email
4 if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
5 echo("$email is a valid email address");
6 }
7 else{
8 echo("$email is not a valid email address");
9 }
10?>
1<?php
2 function checkemail($str) {
3 return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
4 }
5 if(!checkemail("alex@tutorialspoint.com")){
6 echo "Invalid email address.";
7 }
8 else{
9 echo "Valid email address.";
10 }
11?>
1$email = "email@email.fr";
2
3if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
4 $emailErr = "Email invalide";
5}
1$pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
2
3$emailaddress = 'test@gmail.com';
4
5if (preg_match($pattern, $emailaddress) === 1) {
6 // emailaddress is valid
7}
8
1//BE CAREFUL!!!
2//NEVER VALIDATE A EMAIL WITH A NORMAL PREG MATCH
3//I SAW THIS A LOT VALIDATING A EMAIL IS THE BEST TO SEND A EMAIL
4//AND VERIFY
5//BECAUSE SOMEONE MIGHT HAVE A RIGHT EMAIL THAT DOESNT WORK BECAUSE OF
6//PREG MATCH