Well after some copy pasting and mixing it I think I've got it:
if (!ereg("[-!#$%&'+./0-9=?A-Z_`a-z{|}~]+@{1}([a-z0-9]{1}[a-z0-9-][a-z0-9]{1}.{1})+([a-z]+.){0,1}([a-z]){2,4}$", trim($email)))
Cheers,
Hendricus
Well after some copy pasting and mixing it I think I've got it:
if (!ereg("[-!#$%&'+./0-9=?A-Z_`a-z{|}~]+@{1}([a-z0-9]{1}[a-z0-9-][a-z0-9]{1}.{1})+([a-z]+.){0,1}([a-z]){2,4}$", trim($email)))
Cheers,
Hendricus
How about allowing a space between input?
if (ereg ("[a-zA-ZÀ-ÖØ-öø-ÿ-]{2,}$", $firstname))
doesn't allow a name like "Billy Bob"
One of these days I'll understand this ereg stuff
Cheers,
Hendricus
Originally posted by mcgruff
I'd be interested to hear your comments on the need for complex expression matching. Is there any need to do anything more than a quick check for an "@" and no more than two "." after the "@"?
Hmm, I dunno. Email me at "-#$%~`||}@|_)*&%$.#$%.com" and we'll talk it over....
Hmm, I dunno. Email me at "-#$%~`||}@|_)*&%$.#$%.com" and we'll talk it over....
Couldn't email you so I'll have to post here : )
OK, that's a dog but couldn't people legitimately have "-" "_" "~" aor other special chars in their address which (I presume) the above would block?
My regexp does allow the underscore _ and the hyphen - , but not as the initial character.... I'd never thought about the tilde ~ ? I don't know that I've ever actually seen such an address, but, of course I don't know nearly everything. Anyone got a good article on 'the naming of users.' ?? Seems to me that nowdays the rules are simpler, and the names dumber, than ever. My latest ISP doesn't even allow underscore or hypen in their usernames....
Rgr - it would be good if we could round this thread off with a definitive list of exactly what special chars should be blocked by a validation check.
Coming up with code to block special chars is, I suppose easy enough but I'm still unclear exactly what to block.
Anyone?
I think it is probably easier to list what is allowed. I'm sure about these:
letters
digits
period
hyphen
underscore
hyphen
and of course the @
I don't think ~ is valid.
Thanks XBlue.
Finally, here's a link I just remembered I had for a validation class in case it's useful to anyone:
http://www.killersoft.com/downloads/pafiledb.php?action=viewall
Info on RFC 822 - not sure if this is working:
I found this one at the same site that you were searching originally Hendricus. Seems to work well.
<?php
$string = "user@domain.com";
if(preg_match("/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/",$string))
{
echo "It's a match.";
}
else
{
echo "Not a match";
}
?>
With a friend I tried to create some email addresses on his server:
.....@domain.com is allowed and sending mail works
ben&jerry@domain.com is allowed and sending mail works
procent%@domain.com is a allowed address for the server but outlook crashes
euro€@domain.com is a allowed address for the server but outlook crashes
néw@domain.com is a allowed address for the server but outlook crashes
Lots a stuff is allowed email it seems...
Cheers
Hendricus
PS. how bout that space thing i mentioned above?
Originally posted by xblue
I think it is probably easier to list what is allowed. I'm sure about these:
letters
digits
period
hyphen
underscore
hyphen
and of course the @
I don't think ~ is valid.
There should be a organisation out there which have complete study groups for this... but I couln'dt find a thing on http://www.imc.org
Hendricus
Well the default regexp for adding users on a BSD system is:
[^[a-z0-9_][a-z0-9_-]*$]
Now, methinks that it's 'case insensitive', so one could generalize that UNIX user/mailbox names may start with an alphanumeric character or underscore, and contain underscores, hyphens, and alphanumeric characters...of course, in generalizing, you create a sizeable group of exceptions, I expect....
Originally posted by Hendricus
Well after some copy pasting and mixing it I think I've got it:
if (!ereg("[-!#$%&'+./0-9=?A-Z_`a-z{|}~]+@{1}([a-z0-9]{1}[a-z0-9-][a-z0-9]{1}.{1})+([a-z]+.){0,1}([a-z]){2,4}$", trim($email)))
Cheers,
Hendricus
But if you try to validate an email address of e.g.
me@sub.domain.co.uk it fails.
Anybody know how to get the extra sub-domains included in the ereg script?
mine ->
preg_match('/^\w[-.\w]*\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]{2,4}$/smi' , $string);
Not sure what the point is for having a seperate class for e-mail validation.
Here's mine anyway.
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,7})$", $strEmail)) {
//email is invalid
}