Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Validate newline delimited email list

by philosophia (Sexton)
on Jan 12, 2007 at 21:35 UTC ( [id://594461]=note: print w/replies, xml ) Need Help??


in reply to Re: Validate newline delimited email list
in thread Validate newline delimited email list

the current version of this code looks like

my ($error) = 0; my (@other_addresses) = split( /\n/, $email_list ); foreach (@other_addresses) { my $ok = Email::Valid->address($_); $error++ if(!$ok); print "address($_) = $ok\n"; print "error ".$error."<br>"; } $error_message .= "$error Email list contains an invalid email ad +dress.<br>" if $error;
and gives me

address(test@test.com ) = error 1 address(test2@test.com) = test2@test.com error 1 There was an error with your form submission. 1 Email list contains an invalid email address.


it seems to let every address through whether it is valid or not.

Replies are listed 'Best First'.
Re^3: Validate newline delimited email list
by ikegami (Patriarch) on Jan 12, 2007 at 21:50 UTC

    "test@test.com " is indeed bad. Notice the trailing space? It's easy to fix the address, though.

    sub trim { my ($s) = @_; for ($s) { s/^\s+//; s/\s+$//; return $_; } } ... my @other_addresses = map trim, split( /\n/, $email_list ); ...
      i put the above in my code and

      sub trim;

      at the top of my script.

      I get
      address() = error 1 address() = error 2 There was an error with your form submission.
      shouldn't chomp() remove the trailing space? i've tried chomp($_) and it looks like the space is still there.

      i've tried your suggestion above, and it doesn't seem to populate $_
        No. chomp doesn't remove trailing spaces.
      this gave me a software error, not sure how to deal with it:

      Bareword "trim" not allowed while "strict subs" in use at...
        Sounds like you added the call to the function, but not the function itself??
Re^3: Validate newline delimited email list
by Sagacity (Monk) on Jan 12, 2007 at 22:53 UTC

    Looks to me that this line

    $error++ if(!$ok);

    is merely testing whether $ok exists, which it always does according to the line above it.

    my $ok = Email::Valid->address($_);

    Try testing for the value of $ok that was returned instead.

    if ($ok == 1) {#the rest of your code } else {# code here too if you like }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found