note 38582 added to ref.mail
| From: | ferenczigaboratferenczigabordotcom at rn2 dot php dot net | Date: | Sun, 28 Dec 2003 16:45:54 +0000 |
| Subject: | note 38582 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62610@lists.php.net to get a copy of this message | ||
Hi there,
Here is a simple script, which cheks the given mail address\'s shape. It reports a boolen TRUE,
if the address looks like correct, and reports FALSE, when there is/are illegal character(s); the AT
mark is missing, or duplicated; the DOT is missing, or is on wrong place. Calling after a FALSE
return-value with an empty string (""), it reports the bug.
A sample:
if (!MailAddrCheck ( submitted MailAddress )); { echo MailAddrCheck ("" );} else {
statements... }
(Excuse me for the mixture of the English and Hungarian).
<?php
Function MailAddrCheck ($MailAddr ){
/*Az átvett szóban ellenõrzi, hogy
1. van-e @ jel,
2. nincs-e több @ jel
3. a @ jel után van-e legalább 1 "."
4. nincs-e mail címben tiltott jel (ékezetek, stb.), vagy kizárólag érvényes jel van-e
strtolower() a...z, 0...9, _-+
String paraméterrel meghívva megvizsgálja a a mailcim érvényességét, és logikai változót
ad vissza (hamis, ha hiba van a címben,
de ekkor static változóban beállít egy hibakódot.
Üres string paraméterel nélkül meghívva a hibakód szerinti string tömbelemet ad vissza, ami a
hiba okát írja le.
*/
static $ErrorCode = 0;
$ArrayError = array (
"There is no address!","There is an illegal character!","There are more
than 1 '@' mark!","There is no '@' mark at all!","The domain
name seems to be incorrect: no '.', or just after the '@'!","The
domain name seems to be incorrect: the '.' is just after the '@')!");
//"Nincs cím!","Illegális karakter!","Több, mint 1
'@'jel!","Nincs '@'jel!","A domén név hibásnak tûnik:
nincs '.', vagy az mindjárt a '@' jel után áll!","A domén név
hibásnak tûnik: a '.' mindjárt a '@' jel után áll!");
$LowerMailAddr = strtolower ($MailAddr);
$AcceptedLetters = "0123456789qwertzuiopasdfghjklyxcvbnm-+_.@";
$ParamLen = strlen ($MailAddr);$IsGood = TRUE;
if ($ParamLen>0) { //if paramlen kezdete
//Nem vizsgálom ParamLen típusát, programozáskor jól kell megadni, string legyen.
for ($x=0; $x< $ParamLen; $x++) { //for kezd
//string substr ( string string, int start [, int length])
//int strrpos ( string haystack, string needle)
//Ha nem talál, hamis, ha talál, szám >0, tehát
if ((strpos($AcceptedLetters, substr ($LowerMailAddr, $x, 1))>0)) {$IsGood = $IsGood &&
true;}
else {$IsGood = $IsGood && FALSE;$ErrorCode=1;} //ErrorCode =1, azaz hibás karakter
} //for vége
//@ jelet keres
$VanE_AT = strpos ($LowerMailAddr, "@");
$VanE_AT2 = strrpos ($LowerMailAddr, "@");
if ($VanE_AT>0) { //Van-e @ kezd
if ($VanE_AT < $VanE_AT2) { //Baj van, több @ jel van!
$IsGood = $IsGood && false;$ErrorCode = 2; //ErrorCode = 2, azaz több @ jel van
} //több @ jel if vége
} //Van- e @ vége
else { //Baj van, nincs @ jel
$IsGood = $IsGood && false;$ErrorCode = 3; //ErrorCode = 3, azaz nincs @ jel
} //else vége
//Pontot keres a @ jel után
$VanE_DOT = strrpos ($LowerMailAddr, "."); //Az utolsó "." helye: jó, ha >
mint @ jel helye +1
if (!($VanE_DOT > $VanE_AT+1)) { $IsGood = $IsGood && false;$ErrorCode = 4; } //A domain
név rossz: nincs ., vagy mindjárt a @ után
if (substr ($LowerMailAddr, $VanE_AT+1, 1) == ".") { $IsGood = $IsGood &&
false;$ErrorCode = 5; } //A domain név rossz: "." mindjárt a @ után
} //if paramlen vége
else {$IsGood = $ArrayError[$ErrorCode];}
return $IsGood;
} //függvény vége
?>
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38582
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38582&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38582&report=yes
Search -- http://master.php.net/manage/user-notes.php