[Phpwm] Simple PHP Contact Form
phil at infolinkelectronics.co.uk
phil at infolinkelectronics.co.uk
Wed Oct 14 08:35:47 UTC 2009
Regards,
Phil Beynon
Sales & Operations Director
** Infolink Electronic Systems Ltd.
** S/W Birmingham's Longest Established ISV & VAR
** http://www.infolinkelectronics.co.uk
** Professional Web 2.0 Design & Advanced Hosting Platforms
** http://www.coeus-computica.co.uk
** Affordable Knowledgebase Solutions
** Contact: Sales at infolinkelectronics.co.uk
** Tel / Fax 0121 441 3558
> > if (!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$",
> > $emaila)) error_alert("Invalid Email Address");
>
> My understanding is that there are a million and one regexps to
> validate email addresses and it'd not the right one unless it is very,
> very long.
>
> Yours will fail on eg adresses which look like foo.o'reilly at ....
> (valid) or foo+bar at ... (valid).
Apostrophes in teh first part are also likely to break other things as they
can be seen as a delimiter. Many ISPs thus limit their use.
> And it allows an _ in a domain name which isn't possible. I think
> there are also tlds longer than 4 characters.
Yup there can be trade offs, it will fail on say .museum addresses, however
the only real way to do that is look up the tld against a definitive list
It has to be said when I wrote the code originally I doubt many > 3 char
TLDs actually did exist! :-)
> And ereg is deprecated, as has already been pointed out. Use preg_match
I only actually got that pointed out to me last night by Alex :-)
> You'd have made the regexp easier to write in ' rather than " -
> avoiding \\ escaping blah blah too i think.
Yes but if I had made it perfect as per RFC 2822 it would have looked like;
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01
-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f]
)*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])
?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|
[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\
x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
So yes mine is a lot shorter and is a compromise in some respects - but it
pretty much works in real world environments!
> Sorry if I sound bitchy,
Dont worry about it.
Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Phil Beynon.vcf
Type: text/x-vcard
Size: 636 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/phpwm/attachments/20091014/5cfee46a/attachment.vcf
More information about the Phpwm
mailing list