Well after spending hours scouring the web and winding myself in knots with various regular expressions, I came across an email validation function for PHP which actually seems to almost do the trick - and now it works very nicely after a little modification.
After messing about with lots of functions which claimed to return true for a valid email, I found these tests to be the most gruelling:
admin.@radio1.org
admin@radio1.org.
admin@@radio1.org
@aol.com
this@aol
admin@this.this.this.org.uk
admin@this.info
admin@this.dj
Basically most scripts are going for the complicated route of verifying the number of characters in the known TLD (Top Level Domains) and trip over when it comes to the lesser known ones such as ".museum" and ".arpa" - and the newer domains such as ".info".
The one I have modified came from Devshed: (click here to view the article)
But this one allowed emails like admin@radio1.org. (with a period on the end of the string) to return true.
A small addition to the end of the expression fixed this
[a-zA-Z0-9_-]$
Here is the code:
function validateEmail($val)
{
return(preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+[a-zA-Z0-9_-]$/", $val));
}
This is by no means perfect, but it does the job for me - comments welcome - I am always on the lookout for improvements!
I hope someone finds this helpful -
Robin Brinkler