Advertisement
Guest User

Untitled

a guest
Sep 14th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.29 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Jimmy Lemieux
  5.  * Date: 2015-09-03
  6.  */
  7. $tEmail=array();
  8. $tEmail[0]["courriel"]="jimmy_lemieux@hotmail.com";
  9. $tEmail[0]["nom"]="Lemieux";
  10. $tEmail[0]["prenom"]="Jimmy";
  11.  
  12. $tEmail[1]["courriel"]="vbelandhotmail.com";
  13. $tEmail[1]["nom"]="Beland";
  14. $tEmail[1]["prenom"]="Vincent";
  15.  
  16. $tEmail[2]["courriel"]="ccarpentier@hotmail.com";
  17. $tEmail[2]["nom"]="Carpentier";
  18. $tEmail[2]["prenom"]="Cohan";
  19.  
  20. $tEmail[3]["courriel"]="emilie@hotmail.c";
  21. $tEmail[3]["nom"]="Viel";
  22. $tEmail[3]["prenom"]="Emilie";
  23.  
  24. $tEmail[4]["courriel"]="vincent@hotmailcom";
  25. $tEmail[4]["nom"]="Beland";
  26. $tEmail[4]["prenom"]="Vincent";
  27.  
  28. $tEmail[5]["courriel"]="gabriel@hotmail.com";
  29. $tEmail[5]["nom"]="Murray";
  30. $tEmail[5]["prenom"]="Gabriel";
  31.  
  32. $tEmail[6]["courriel"]="albert@hotmail.com";
  33. $tEmail[6]["nom"]="Sanson";
  34. $tEmail[6]["prenom"]="Albert";
  35.  
  36. $tEmail[7]["courriel"]="jimmy,lemieux@live.ca";
  37. $tEmail[7]["nom"]="Lemieux";
  38. $tEmail[7]["prenom"]="Jimmy";
  39.  
  40. $tEmail[8]["courriel"]="jim?lemieux@outlook.com";
  41. $tEmail[8]["nom"]="Lemieux";
  42. $tEmail[8]["prenom"]="Jimmy";
  43.  
  44. $tEmail[9]["courriel"]="jimmy:lem@hotmail.com";
  45. $tEmail[9]["nom"]="Lemieux";
  46. $tEmail[9]["prenom"]="Jimmy";
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. function validerCourriel($unCourriel)
  54. {
  55.    $codeErreur = 0;//0 = courriel valide
  56.    $positionAt = null;
  57.    $finCourriel = null;
  58.     $codeErreur = verifierCarSpeciaux($unCourriel);
  59.     if ($codeErreur == 0){
  60.         $codeErreur = verifierAt($unCourriel);
  61.         if ($codeErreur == 0){
  62.             $positionAt = strpos($unCourriel,"@");
  63.             $finCourriel = substr($unCourriel,$positionAt+1);
  64.             $codeErreur = verifierPoint($finCourriel);
  65.             if ($codeErreur == 0){
  66.                 $codeErreur = verifierFin($finCourriel);
  67.             }
  68.         }
  69.     }
  70.     return $codeErreur;
  71. }
  72.  
  73. function verifierCarSpeciaux($unCourriel)
  74. {
  75. $codeErreur = 0;
  76. $carSpeciaux =array("/",":",",",";"," ","?");
  77. for($cpt=0; $cpt < count($carSpeciaux) && $codeErreur==0;$cpt++)
  78. {
  79.     if (strpos($unCourriel, $carSpeciaux[$cpt]) != false)
  80.     {
  81.         $codeErreur = 1;
  82.     }
  83.    
  84. }
  85.     return $codeErreur;
  86. }
  87. function verifierAt($unCourriel)
  88. {
  89.    
  90. $codeErreur = 0;
  91. $posAt = strpos($unCourriel, "@");
  92. if ($posAt > 0)
  93. {
  94.     if (strpos($unCourriel, "@", $posAt + 1) != false)
  95.     {
  96.         $codeErreur=2;
  97.     }
  98. }
  99.     else
  100.     {
  101.        $codeErreur=2;
  102.     }
  103.    
  104.     return $codeErreur;
  105. }
  106.  
  107.  
  108. function verifierPoint($finCourriel)
  109. {
  110.     //finCourriel est la portion de l'adresse après le @
  111.     $codeErreur=0;
  112.     if (strpos($finCourriel, ".") <= 0) // -1: pas de point, 0: un point en 1ere position
  113.     {
  114.        $codeErreur = 3;
  115.     }
  116.     return $codeErreur;
  117. }
  118.  
  119. function verifierFin($finCourriel)
  120. {
  121. //finCourriel est la portion de l'adresse après le @
  122. $codeErreur=0;
  123. $posPoint=strrpos($finCourriel,".");
  124. $chaineFin =substr($finCourriel,$posPoint+1);
  125. if (strlen($chaineFin) < 2)
  126. {
  127.     $codeErreur = 4;
  128. }
  129. return $codeErreur;
  130. }
  131.  
  132.  
  133. ?>
  134.     <!doctype html>
  135.     <html>
  136.  
  137.     <head>
  138.         <meta charset="utf-8">
  139.         <title>Courriel</title>
  140.         <style>
  141.             table{
  142.                 text-align:center;
  143.             }
  144.             .erreur{
  145.                 color:red;
  146.             }
  147.         </style>
  148.     </head>
  149.  
  150.     <body>
  151.         <table>
  152.            
  153.  
  154.                 <tr>
  155.                     <th>Nom</th>
  156.                     <th>Prénom</th>
  157.                     <th>Courriel</th>
  158.                     <th>Code d'erreur</th>
  159.  
  160.                 </tr>
  161.             <?php
  162.             for($cpt=1;$cpt<count($tEmail);$cpt++)
  163.             {
  164.             ?>
  165.                 <tr>
  166.                     <td>
  167.                         <?php
  168.             echo $tEmail[$cpt]["nom"];
  169.             ?>
  170.                     </td>
  171.                     <td>
  172.                         <?php
  173.             echo $tEmail[$cpt]["prenom"];
  174.             ?>
  175.                     </td>
  176.  
  177.                     <td>
  178.                         <?php
  179.             echo $tEmail[$cpt]["courriel"];
  180.             ?>
  181.                     </td>
  182.  
  183.  
  184.  
  185.                     <td class="erreur">
  186.                         <?php
  187.             echo validerCourriel($tEmail[$cpt]["courriel"]);
  188.             ?>
  189.                     </td>
  190.                 </tr>
  191.                 <?php
  192.             }
  193.             ?>
  194.         </table>
  195.     </body>
  196.  
  197.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement