login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Reguliere expressies > E-mail controle

E-mail controle

Auteur: Thomas - 26 augustus 2004 - 15:33 - Gekeurd door: Joel - Hits: 7888 - Aantal punten: 3.40 (5 stemmen)




Deze functie controleert of een e-mailadres wel geldig is. Zoja, returneert hij TRUE.

Code:
Versie van mij:
  1. <?php
  2. function check_email($in) {
  3. $patroon = "/^([a-z0-9_-]+\.)*[a-z0-9_-]+@([a-z0-9_-]{2,}\.)+([a-z0-9_-]{2,})$/i";
  4. return preg_match($patroon, $in);
  5. }
  6. ?>


Versie van Joël:
  1. <?php
  2. function control_email($address) {
  3. list($local, $host) = explode("@", $address);
  4. $pattern_local = "^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$";
  5. $pattern_host = "^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$";
  6. $match_local = eregi($pattern_local, $local);
  7. $match_host = eregi($pattern_host, $host);
  8.  
  9. if($match_local && $match_host) {
  10. return 1;
  11. } else {
  12. return 0;
  13. }
  14. }
  15. ?>


En zo kan je hem gebruiken:
  1. <?php
  2. // Mijn versie
  3. if(check_email("info@sitemasters.be")) {
  4. echo "Adres ok.";
  5. }
  6.  
  7. // Joël zijn versie
  8. if (control_email("info@sitemasters.be")) {
  9. echo "Het e-mailadres is correct!\n";
  10. }
  11. ?>

Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (13)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.036s