As others have mentioned, adding a single rule to your checks is unlikely to be an effective way of stopping spam - you may want to consider captchas, established software to prevent spam, and so on, instead of trying to roll your own.

Having said, that, regexes are also not really a good way to parse email addresses, which is why I would use Email::Address; you may also be interested in Email::Valid (which isn't perfect either, but still better than hand-rolled checks).

use warnings; use strict; use Email::Address; sub countdots { my @addrs = Email::Address->parse(shift); die "expected exactly one address" unless @addrs==1; my $x = (my $tmp = $addrs[0]->user) =~ tr/././; my $y = ($tmp = $addrs[0]->host) =~ tr/././; return wantarray ? ($x,$y) : $x+$y; } use Test::More; my @tests = ( ['test@gmail.com', 0, 1], ['test.test@gmail.com', 1, 1], ['test.test.test@gmail.com', 2, 1], ['test.test.test.test@gmail.com', 3, 1], ['test.test.test.test.test@gmail.com', 4, 1], ['test@foo.bar.com', 0, 2], ['test.test@foo.bar.com', 1, 2], ); plan tests => 2*@tests+1; for my $t (@tests) { my ($ad, $exp_x, $exp_y) = @$t; my ($got_x, $got_y) = countdots($ad); is $got_x, $exp_x; is $got_y, $exp_y; } is countdots($tests[0][0]), $tests[0][1]+$tests[0][2];

In reply to Re: Stopping excessive periods in email by haukex
in thread Stopping excessive periods in email by htmanning

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.