Search code examples
validationemailemail-validationwell-formed

Check well formatted email address


I have a text file of e-mails like this:

10:info@example.com;dev@example.com
12:john@host.com; "George <g.top@host.com>" 
43:jim.p@web.com.;sue-allen@web.com
...

I want to check whether the list contains well formatted entries. Do you know any tool or web-service to check and give me a list of invalid addresses?

Update Dear all, thank you for your input. I was really looking for a basic syntax check, so I will stay with Rafe's idea (I will do it with Java).


Solution

  • I wrote a simple Perl script that uses the Email::Address module to validate these addresses:

    #!/usr/bin/env perl
    
    use Email::Address;
    
    while (<>) {
        chomp;
        @addresses = split /\;/;
    
        foreach my $address (@addresses) {
            if (!Email::Address->parse($address)) {
                print $address, "\n";
            }
        }
    }
    

    You'll just need to install the module. Its home page is:

    http://emailproject.perl.org/wiki/Email::Address