[GRATIS] Check email

Gestart doorSanderc10 reacties28 weergaven

11 berichten · pagina 1 van 1

Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik heb weer eens een klein scriptje gemaakt voor in jou aanmeld pagina!
Met dit script kan je checken of een email wel een correcte email is!

Demo: http://www.dylanproductions.nl/sander/email.php

Code:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/* 
*FUNCTIE = Checken of de ingegeven email wel een correcte email is
*Auteur = Sander C.
*Laatste Update = 23/06/2012
*/[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700]){[/COLOR]
[COLOR= #FF8000]//Checken of er een apenstaartje staat in de email[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #DD0000]@[/COLOR][COLOR= #007700]) ===[/COLOR] false[COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Er staat geen apenstaartje in je e-mail, dus het is geen e-mail. Je bent niet door de controle![/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]//Checken of er wel een punt staat in de email (voor .com etc.)    [/COLOR]
    [COLOR= #007700]}[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/stristr"]stristr[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #DD0000].[/COLOR][COLOR= #007700]) ===[/COLOR] false[COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Er staat geen [/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000] in je e-mail. Dat betekent dat je email vanachter geen extenstie heeft[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]//Checken of de email zeker 8 karakters heeft, want k@i.p kan niet echt bestaan ;)[/COLOR]
    [COLOR= #007700]}[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]email[/COLOR][COLOR= #007700]]) <[/COLOR] [COLOR= #0000BB]8[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]Je e-mail is te kort om een e-mail te kunnen zijn![/COLOR][COLOR= #007700];
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000] In orde[/COLOR][COLOR= #007700];
    }
}[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
?>
<form method=post action=#>
    <input type="text" name="email">
    <input type="submit" value="Check">
</form>
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>


De commentaar heb ik erbij gezet zodat jullie weten voorwat het dient.
Het is een best simpel script maar toch yummie.

Veel succes
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoiets doe je met preg_match, niet met ifjes.

Je kan, hier trouwens ook gewoon dit opgeven:

.@.@.@.@


toevoeging op 23 juni 2012, 12:31:48:

[COLOR= #0000BB]<?php 
$email[/COLOR] [COLOR= #007700]=[/COLOR] "abc123[COLOR= #007700]@[/COLOR]lolhaha"[COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Invalid email address 
//$email = "somebody@somesite.com"; // Valid email address 
// Set up regular expression strings to evaluate the value of email variable against[/COLOR]
[COLOR= #0000BB]$regex[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/[/COLOR][COLOR= #007700];[/COLOR] 
[COLOR= #FF8000]// Run the preg_match() function on regex against the email address[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$regex[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$email[/COLOR][COLOR= #007700])) {[/COLOR]
     [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$email[/COLOR] [COLOR= #007700].[/COLOR] " is a valid email[COLOR= #007700].[/COLOR] We can accept it[COLOR= #007700].[/COLOR]"[COLOR= #007700];
}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR] 
     [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$email[/COLOR] [COLOR= #007700].[/COLOR] " is an invalid email[COLOR= #007700].[/COLOR] Please try again[COLOR= #007700].[/COLOR]"[COLOR= #007700];
}[/COLOR] 
?>


Zo hoort het.
Bron: http://www.developphp.com/view_lesson.php?v=224
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Beter gebruik je dit:

[COLOR= #0000BB]<?php[/COLOR]
filter_var[COLOR= #007700]([/COLOR][COLOR= #DD0000]"some@address.com"[/COLOR][COLOR= #007700],[/COLOR] FILTER_VALIDATE_EMAIL[COLOR= #007700])[/COLOR]
?>


@Antonn smile
0
Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
als je lol.lol@lol doet, zegt ie in orde, maar dat is niet zo
0
Berichten
409
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dit heb ik:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] is_email[COLOR= #007700]([/COLOR][COLOR= #0000BB]$em[/COLOR][COLOR= #007700]){[/COLOR]
    
    [COLOR= #0000BB]$ema[/COLOR] [COLOR= #007700]=[/COLOR] filter_var[COLOR= #007700]([/COLOR][COLOR= #0000BB]$em[/COLOR][COLOR= #007700],[/COLOR] FILTER_VALIDATE_EMAIL[COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$ema[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] FALSE[COLOR= #007700];
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] TRUE[COLOR= #007700];
    }
}[/COLOR]
?>


[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR]is_email[COLOR= #007700]([/COLOR][COLOR= #0000BB]$email[/COLOR][COLOR= #007700]))
    {[/COLOR]
        [COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Je hebt een ongelige e-mail ingevoerd!"[/COLOR][COLOR= #007700];
    }[/COLOR]

?>


Werkt ook gewoon.
0
Berichten
1.053
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
@Fitim die is uit de crimeclub source.
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dankje, had dit net nodig biggrin
toevoeging op 23 juni 2012, 19:07:38:
Dit rekent ie ook als: In Orde (88888888@.)
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Als je het perse in een function wil doe het dan zo...

function isEmail($a)
   {
      return filter_var($a, FILTER_VALIDATE_EMAIL);
   }
0
Berichten
3.074
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Fitim schreef:
Dit heb ik:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] is_email[COLOR= #007700]([/COLOR][COLOR= #0000BB]$em[/COLOR][COLOR= #007700]){[/COLOR]
    
    [COLOR= #0000BB]$ema[/COLOR] [COLOR= #007700]=[/COLOR] filter_var[COLOR= #007700]([/COLOR][COLOR= #0000BB]$em[/COLOR][COLOR= #007700],[/COLOR] FILTER_VALIDATE_EMAIL[COLOR= #007700]);[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$ema[/COLOR][COLOR= #007700]){[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] FALSE[COLOR= #007700];
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] TRUE[COLOR= #007700];
    }
}[/COLOR]
?>


[COLOR= #0000BB]<?php[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR]is_email[COLOR= #007700]([/COLOR][COLOR= #0000BB]$email[/COLOR][COLOR= #007700]))
    {[/COLOR]
        [COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"Je hebt een ongelige e-mail ingevoerd!"[/COLOR][COLOR= #007700];
    }[/COLOR]

?>


Werkt ook gewoon.

Je kan het ook object geörienteerd met een class doen.

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/class"]class[/URL] Filter
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$email[/COLOR][COLOR= #007700];[/COLOR]

    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] setEmail[COLOR= #007700]([/COLOR][COLOR= #0000BB]$email[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]email [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$email[/COLOR][COLOR= #007700];
    }[/COLOR]

    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] validateEmail[COLOR= #007700]()
    {[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] filter_var[COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]email[COLOR= #007700],[/COLOR] FILTER_VALIDATE_EMAIL[COLOR= #007700]);
    }
}[/COLOR]

[COLOR= #0000BB]$email[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]example@email.com[/COLOR][COLOR= #007700];[/COLOR]

[COLOR= #0000BB]$filter[/COLOR] [COLOR= #007700]= new[/COLOR] Filter[COLOR= #007700]();[/COLOR]
[COLOR= #0000BB]$filter[/COLOR][COLOR= #007700]->[/COLOR]setEmail[COLOR= #007700]([/COLOR][COLOR= #0000BB]$email[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$validateEmail[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$filter[/COLOR][COLOR= #007700]->[/COLOR]validateEmail[COLOR= #007700]();[/COLOR]
?>


Maar het is een beetje overbodig om classes te schrijven voor zon kleine functie.

Verder leuk gedaan, Sander! Probeer alleen je accolades beter uit te lijnen. smile
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Indd leuk gemaakt, maar op foute manier en nog steeds niet goed. Als je het toch echt met ifjes wilt doen raa ik je explode en stelen aan. Maar toch lijken de bovestaand genoemde opties me sneller en beter.

Ook maak je hier dan eter een functie voor, en gebruik je " in de HTML ipv. .
0
Berichten
69
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
bedankt voor het scriptje biggringa ik gebruiken voor mn systteem yummie
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren