Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Stopping excessive periods in email

by haukex (Bishop)
on Jul 16, 2021 at 20:42 UTC ( #11135082=note: print w/replies, xml ) Need Help??

in reply to Stopping excessive periods in email

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 = ( ['', 0, 1], ['', 1, 1], ['', 2, 1], ['', 3, 1], ['', 4, 1], ['', 0, 2], ['', 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];

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135082]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-09-17 04:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found