in reply to •Re: Re: special handling with regular expressions
in thread special handling with regular expressions

I don't think the idea of handling form text value differently if it looks like an email addess is particularly wise, but if the OP is determined to go with such an approach, then my regex above is as good a heurstic as anything else. Sure, you could use a CPAN module that can correctly parse RFC822 addresses, but since we are dealing with a web form where users have typed in stuff by hand, its fairly unlikely they're typing the full RFCish stuff involving quoting, <> etc.
  • Comment on Re: special handling with regular expressions

Replies are listed 'Best First'.
•Re: Re: special handling with regular expressions
by merlyn (Sage) on May 10, 2004 at 15:02 UTC
    Your regex rejects:
    "Randal L. Schwartz"@vms-relay.stonehenge.comm
    And if that was my legitmate email address because of the way my internal company mailing system was set up, you've now given me no opportunity to use your web site. You made two common mistakes in your regex:
    • \w doesn't match hyphen, and yet hyphen can easily appear in a domain name.
    • Legitimate email addresses might have embedded spaces.
    The proper answer here is to not make things up and use the FAQ answers. Don't just invent your own thing.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Given that this field is overloaded to take either a description or an email address, I have a feeling that the "correct" regexp is going to treat some things as email addresses that weren't intended as such. And it sounds as if the primary use of the field is for descriptions, so it may be wise to err the other way.

      Update: an example would be:

      I also notified the guys at <foo@example.com>