How to validate an email address with perl


(Stéphane de Labrusse) #1

I need to validate several email addresses in my perl template, on sme server I use to validate them by esmith::util::isValidEmail but on nethserver it has been removed

I can use perl-Email-Valid from epel for this purpose but I prefer to use a solution already installed.

For those who want to know why I didn’t validate it in Nethgui, I use a ‘textArea’ because I want to save several addresses (one address per line) and the available validators cannot work with this type of box. I suppose that kind of validator are workable for the ‘textInput’.

I have had the same validation issues with a textArea for IP also, but I used http://wiki.nethserver.org/doku.php?id=developer:net:ipv4addr for validating in my perl template.


(Giacomo Sanchietti) #2

The default installation already has perl-Mail-RFC822-Address package.

From the official doc (tested, it works with single quotes)

use Mail::RFC822::Address qw(valid validlist);

if (valid("pdw@ex-parrot.com")) {
  print "That's a valid address\n";
}

if (validlist("pdw@ex-parrot.com, other@elsewhere.com")) {
  print "That's a valid list of addresses\n";
}

See:
http://search.cpan.org/~pdwarren/Mail-RFC822-Address-0.3/Address.pm

@davidep any other hint?


(Davide Principi) #3

I had to recompile that package on ns7. I don’t know why nethserver-base requires it, but I’d like getting rid of it :smile:

We should investigate that dependency… Perhaps perl-Email-Valid from EPEL could be a good substitute.


(Stéphane de Labrusse) #4

I did some doc on the wiki in the developer area