[thelist] PHP Form Validation

shawn allen shawn at alterior.net
Mon Jan 6 13:57:07 CST 2003


quoth Hans-Frédéric Fraser:
> On 1/6/03 11:17 AM, "Andrew Maynes" <andrew at humanbehaviour.co.uk> wrote:
> > The tell a friend form needs to validate two email addresses, the
> > sender's and the sender's friend.  At the moment I only have this:
> >
> > /*e-mail´s validity is check with this */
> > if (!eregi ("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,4}$",
> > $email)) $error_message = "A valid e-mail address is required.";

I'd recommend you not validate email addresses at all unless you can
properly account for every possible, *valid* variation according to the
RFC[1]. What annoys me about many sites is the use of limited regular
expressions that keep me from entering (perfectly valid) addresses like
'shawn+foo at alterior.net', in which I use the '+foo' to track the
distribution of my address after posting it to a particular website, or
just to simplify procmail recipes on my end.

An alternative solution is to simply have the user verify their address
with a duplicate field. If they can type in an invalid email address
twice in a row, well, they've got problems. IMO, of course ;)

[1] http://www.ietf.org/rfc/rfc2822.txt

--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list