Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Jimmy Lemieux
- * Date: 2015-09-03
- */
- $tEmail=array();
- $tEmail[0]["courriel"]="jimmy_lemieux@hotmail.com";
- $tEmail[0]["nom"]="Lemieux";
- $tEmail[0]["prenom"]="Jimmy";
- $tEmail[1]["courriel"]="vbelandhotmail.com";
- $tEmail[1]["nom"]="Beland";
- $tEmail[1]["prenom"]="Vincent";
- $tEmail[2]["courriel"]="ccarpentier@hotmail.com";
- $tEmail[2]["nom"]="Carpentier";
- $tEmail[2]["prenom"]="Cohan";
- $tEmail[3]["courriel"]="emilie@hotmail.c";
- $tEmail[3]["nom"]="Viel";
- $tEmail[3]["prenom"]="Emilie";
- $tEmail[4]["courriel"]="vincent@hotmailcom";
- $tEmail[4]["nom"]="Beland";
- $tEmail[4]["prenom"]="Vincent";
- $tEmail[5]["courriel"]="gabriel@hotmail.com";
- $tEmail[5]["nom"]="Murray";
- $tEmail[5]["prenom"]="Gabriel";
- $tEmail[6]["courriel"]="albert@hotmail.com";
- $tEmail[6]["nom"]="Sanson";
- $tEmail[6]["prenom"]="Albert";
- $tEmail[7]["courriel"]="jimmy,lemieux@live.ca";
- $tEmail[7]["nom"]="Lemieux";
- $tEmail[7]["prenom"]="Jimmy";
- $tEmail[8]["courriel"]="jim?lemieux@outlook.com";
- $tEmail[8]["nom"]="Lemieux";
- $tEmail[8]["prenom"]="Jimmy";
- $tEmail[9]["courriel"]="jimmy:lem@hotmail.com";
- $tEmail[9]["nom"]="Lemieux";
- $tEmail[9]["prenom"]="Jimmy";
- function validerCourriel($unCourriel)
- {
- $codeErreur = 0;//0 = courriel valide
- $positionAt = null;
- $finCourriel = null;
- $codeErreur = verifierCarSpeciaux($unCourriel);
- if ($codeErreur == 0){
- $codeErreur = verifierAt($unCourriel);
- if ($codeErreur == 0){
- $positionAt = strpos($unCourriel,"@");
- $finCourriel = substr($unCourriel,$positionAt+1);
- $codeErreur = verifierPoint($finCourriel);
- if ($codeErreur == 0){
- $codeErreur = verifierFin($finCourriel);
- }
- }
- }
- return $codeErreur;
- }
- function verifierCarSpeciaux($unCourriel)
- {
- $codeErreur = 0;
- $carSpeciaux =array("/",":",",",";"," ","?");
- for($cpt=0; $cpt < count($carSpeciaux) && $codeErreur==0;$cpt++)
- {
- if (strpos($unCourriel, $carSpeciaux[$cpt]) != false)
- {
- $codeErreur = 1;
- }
- }
- return $codeErreur;
- }
- function verifierAt($unCourriel)
- {
- $codeErreur = 0;
- $posAt = strpos($unCourriel, "@");
- if ($posAt > 0)
- {
- if (strpos($unCourriel, "@", $posAt + 1) != false)
- {
- $codeErreur=2;
- }
- }
- else
- {
- $codeErreur=2;
- }
- return $codeErreur;
- }
- function verifierPoint($finCourriel)
- {
- //finCourriel est la portion de l'adresse après le @
- $codeErreur=0;
- if (strpos($finCourriel, ".") <= 0) // -1: pas de point, 0: un point en 1ere position
- {
- $codeErreur = 3;
- }
- return $codeErreur;
- }
- function verifierFin($finCourriel)
- {
- //finCourriel est la portion de l'adresse après le @
- $codeErreur=0;
- $posPoint=strrpos($finCourriel,".");
- $chaineFin =substr($finCourriel,$posPoint+1);
- if (strlen($chaineFin) < 2)
- {
- $codeErreur = 4;
- }
- return $codeErreur;
- }
- ?>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Courriel</title>
- <style>
- table{
- text-align:center;
- }
- .erreur{
- color:red;
- }
- </style>
- </head>
- <body>
- <table>
- <tr>
- <th>Nom</th>
- <th>Prénom</th>
- <th>Courriel</th>
- <th>Code d'erreur</th>
- </tr>
- <?php
- for($cpt=1;$cpt<count($tEmail);$cpt++)
- {
- ?>
- <tr>
- <td>
- <?php
- echo $tEmail[$cpt]["nom"];
- ?>
- </td>
- <td>
- <?php
- echo $tEmail[$cpt]["prenom"];
- ?>
- </td>
- <td>
- <?php
- echo $tEmail[$cpt]["courriel"];
- ?>
- </td>
- <td class="erreur">
- <?php
- echo validerCourriel($tEmail[$cpt]["courriel"]);
- ?>
- </td>
- </tr>
- <?php
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement