Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

As told by others, you should check the RFC or the module, or the module code. Anyway, if you are reinventing the wheel to learn something new, I'll tell you how I'd do it in the simplest case: address@some.domain.here

First of all, there should be just one "@", and if you want to avoid source routing you should also be sure there are no "%" on the right of the @.

you should check that there actually are characters before the @

top level domain should be two, three or four alphabetical chars (or you should get a list of TLD and check for them; guess how -hint: use an hash).

you should really have something more than only a top level domain on the right of @: a dot must be there, and there should be at least one alphanumeric character (plus the "-") between @ and the dot

Last but not least: no spaces are allowed

So, a regexp could be:

use strict ; use warnings ; my @addresses = qw(you@somewhere.com me@here me@here@there@everywhere why@ @.it) ; foreach (@addresses) { print "$_ is " ; print /^\S+\@([a-z-]+\.)+[a-z]{2,4}$/ ? "GOOD!!!" : "bad" ; print "\n" ; }

This yelds:

you@somewhere.com is GOOD!!! me@here is bad me@here@there@everywhere is bad why@ is bad @.it is bad

Please remember this is only the simplest case!!!, mail addresses syntax is far more complicated than one would expect reading common addresses. The best way to understand it is to try to write a spam filter for personal use :-)

Have fun!

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->made($love) ;
}


In reply to Re: email check by bronto
in thread email check by mr2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-28 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found