From owner-freebsd-questions Wed Jan 2 14:23:59 2002 Delivered-To: freebsd-questions@freebsd.org Received: from smtp006pub.verizon.net (smtp006pub.verizon.net [206.46.170.185]) by hub.freebsd.org (Postfix) with ESMTP id BF35837B41C for ; Wed, 2 Jan 2002 14:23:56 -0800 (PST) Received: from verizon.net ([199.171.52.20]) by smtp006pub.verizon.net with ESMTP ; id g02MNnd13161 Wed, 2 Jan 2002 16:23:49 -0600 (CST) Message-ID: <3C33881E.9030506@verizon.net> Date: Wed, 02 Jan 2002 17:22:22 -0500 From: Simon Morton Reply-To: smorton@acm.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.7) Gecko/20011221 X-Accept-Language: en,pdf,zh-CN,de-DE,zh-TW,zh, zh- MIME-Version: 1.0 To: freebsd-questions@FreeBSD.ORG Subject: Re: Regex Question - email matching References: <200201021839.g02IdLG68388@lurza.secnetix.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Don't worry, I won't be filtering any email addresses using this code. I just typed it in off the top of my head as an improvement over the regexp than was originally posted. Not surprising that a couple of the finer points of RFC 2822 escaped me ;-) The "correct" regexp for validating email addresses is left as an exercise for the reader. Simon Oliver Fromme wrote: > Simon Morton wrote: > > if ( $email =~ /^([\w\.\-]+)\@([\w\.\-]+)\.([[:alpha:]]+)$/ ) { > > [...] > > } else { > > print "Invalid email address\n"; > > Then you would be rejecting a lot of valid addresses. > For example, they can contain "+". On the other hand, > it would accept "_" in domain names which is illegal. > > Please -- if someone is accepting or rejecting email > addresses based on some regular expression, _PLEASE_ > read RFC 2822 first, and in particular section 3.4 > titled "address specification". Otherwise you might > cause some trouble and grief to your users. > > The format of valid email addresses is more complicted > than many people think. > > Regards > Oliver > > -- http://www.SimonMorton.com smorton at acm dot org \rm -rf /bin/laden To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message