tart has asked for the wisdom of the Perl Monks concerning the following question:
Cheers!use strict; use warnings; my @id = (' @itx.org ', 'tart@itx.com', 't_art@hotmail.com'); my @validid; foreach(@id) { my $valid = validate($_); if($valid) { push(@validid, $valid); } else { print "Invalid id $_\n"; exit; } } print "Valid IDs: @validid\n"; sub validate { my $id = shift; $id =~ s/\s+$//; $id =~ s/^\s+//; if($id =~ /^@|^\./) { return; } elsif($id =~ /^.*\@itx\.com/i) { if($id !~ /ca$/) { return "$id.ca" if($id =~ /com$/); } else { return "$id"; } } elsif($id =~ /^.*\@\w+\.(?:com|org|net)/) { return "$id"; } return; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Validate email id
by jwkrahn (Abbot) on Jul 15, 2010 at 00:27 UTC | |
|
Re: Validate email id
by roboticus (Chancellor) on Jul 15, 2010 at 11:37 UTC |