Page 1 of 1
Anyone have an Email String Validation Routine ?
Posted: Sun Aug 18, 2002 4:33 pm
by HUWUWA
Hi guys, I'm just wondering if anyone has a code snippet for validating an Email string. You know, checking for the '@' symbol, and a '.' and making sure the '@' symbol isn't first and the whole string is a certain length, etc.
I guess I can program it myself but if there is a solid one already I may as well use it
Thanks.
Posted: Sun Aug 18, 2002 4:50 pm
by phpPete
Code: Select all
<?
// check if email address is valid
function isEmailInvalid($val)
{
// regex for email validation
$pattern =
"/^(їa-zA-Z0-9])+(ї\.a-zA-Z0-9_-])*@(їa-zA-Z0-9_-])+(\.їa-zA-Z0-9_-]+)+/";
// match?
if(preg_match($pattern, $val))
{
return 0;
}
else
{
return 1;
}
}
?>
Posted: Sun Aug 18, 2002 5:06 pm
by HUWUWA
Hell Yeah Pete,
It works great, thanks man. Now I just wish I understood it
I'll use it as is though. Thanks again.
Posted: Sun Aug 18, 2002 5:16 pm
by phpPete
Here's a good tutorial at
PHP Builder
It's straight forward...it deals with ereg, but you can modify for preg no problem ( preg is faster ).
Glad to help,
Regards,
PAS
Posted: Sun Aug 18, 2002 6:06 pm
by gotDNS
Sorry to be extremely picky about this, but I must: what the HELL is the point of e-mail validation!? I mean really...unless there was some way to make sure that the actual person OWNED the e-mail adress they put in...it is COMPLETELY pointless. So say i put in the letter 'x'....your validation script wastes SPACE and TIME, checking for certain things. So it tells me i need an '@' symbol with stuff before and after it, etc. So I go back and write '
bob@aol.com'...CONGRATULATIONS, my e-mail address was incorrect, yet it was accepted anyway...thus proving that your validation is pointless!
I somebody wants to BS an e-mail address, the only thing u are doing is making it take 5 seconds longer.......
So, screw the idea
later on, -Brian
Posted: Sun Aug 18, 2002 6:10 pm
by JPlush76
brian, I think its to save people from mispelling their email address
I had many entries where people forgot the @ symbol or put me@aol and forgot the.com or made some other mistake in their address. if someone wants to put a bad addy in, they always can but at least make them put it in the right format

Posted: Sun Aug 18, 2002 6:35 pm
by phpPete
Site registration & confirmations...
confirmation of registration on a website by returning the "Welcome" email sent to the validated email address.
Posted: Sun Aug 18, 2002 6:36 pm
by HUWUWA
Of course it cannot totally validate a real email address but it does make the form look professional. At least you won't have idiots entering simply 'Joe' as their email address.
In my case only people trying to contact me will use the form so I don't mind the test.
Can you imagine how unprofessional your site would look if a guy entered 'Death' as their email address and the mail() function actually went through ?