Solved

Email Validation Help with command line usage in Ubuntu

Posted on 2010-09-05
8
1,006 Views
Last Modified: 2013-12-06
Hi,

I've been searching for a while now for an optimal way to clean up a list of emails and came across two sources that to me seem to provide the best possible solution.

#1) http://www.linuxjournal.com/article/9585?page=0,3
#2) http://php-email-address-validation.googlecode.com/svn/trunk/EmailAddressValidator.php

I chose to try the second one but I'm not quite sure how to use this script on the command line. I run Ubuntu through virtual box and I need some help with how I would run this scrip.

I saved the script (#2) in a local directory as emailvalidator.php and have another file with emails called emailcheck.txt.

What command would I need to use to call this script in the gnome terminal? Thank you in advance



0
Comment
Question by:faithless1
  • 5
  • 2
8 Comments
 
LVL 3

Expert Comment

by:ssapkota
ID: 33607666
If you are searching for a tool in gnome-terminal.
Then I better suggest you to use the power of regular expression from tools like grep/sed/awk.
Eg: if  you have a list of email addresses in a file(one in each line), you can run the following commands to filter the valid ones only.
cat file | grep -P '[a-zA-Z][a-zA-Z0-9\._-]+@[a-zA-Z0-9][a-zA-Z0-9\.]+'

[Note: this is just a quick solution and need some more tweak to perform flawlessly.]

Or if its possible can you share a chunk from your source (can be modified as well), and we can give you a full fledged solution.
Those scripts that you found are useful for php based online solution.
0
 
LVL 3

Expert Comment

by:ssapkota
ID: 33607669
If you want to read about perl based regular expression:
http://www.troubleshooters.com/codecorn/littperl/perlreg.htm
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 33608111
Here is a teaching example showing how to validate an email address in PHP.  There are many such email validator scripts on the WWW and almost all of them are wrong in one way or another.

Good luck with it, ~Ray
<?php // RAY_email_validation.php
error_reporting(E_ALL);

// A FUNCTION TO TEST FOR A VALID EMAIL ADDRESS, RETURN TRUE OR FALSE

function check_valid_email($email)
{
    // IF PHP 5.2 OR ABOVE, WE CAN USE THE FILTER
    // MAN PAGE: http://us3.php.net/manual/en/intro.filter.php
    if (strnatcmp(phpversion(),'5.2') >= 0)
    {
        if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) return FALSE;
    }
    else
    {
        $regex = '/^[A-Z0-9_-][A-Z0-9._-]*@([A-Z0-9][A-Z0-9-]*\.)+[A-Z\.]{2,6}$/i';
        if (!preg_match($regex, $email)) return FALSE;
    }

    // FILTER or PREG DOES NOT TEST IF THE DOMAIN OF THE EMAIL ADDRESS IS ROUTABLE
    $domain = explode('@', $email);
    if ( checkdnsrr($domain[1],"MX") || checkdnsrr($domain[1],"A") ) return TRUE;

    // EMAIL NOT ROUTABLE
    return FALSE;
}

// DEMONSTRATE THE FUNCTION IN ACTION
$e = '';
if (!empty($_GET["e"]))
{
    $e = $_GET["e"];
    if (check_valid_email($e))
    {
        echo "<br/>VALID: $e \n";
    } else
    {
        echo "<br/>BOGUS: $e \n";
    }
}
// END OF PHP - PUT UP THE FORM
?>
<form method="get">
TEST A STRING FOR A VALID EMAIL ADDRESS:
<input name="e" value="<?php echo $e; ?>" />
<input type="submit" />
</form>

Open in new window

0
 

Author Comment

by:faithless1
ID: 33608167
Thanks for the responses.

- Ray, how would I run this script on the command line in unix?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33608176
Sorry - I do not know.  I do not use the command line; I use PHP scripts.  Since this was posted in the PHP zone I could only help with a PHP script.  Maybe one of the other experts could show you how to adapt it to command-line execution.  I am sure it is possible.
0
 
LVL 3

Expert Comment

by:ssapkota
ID: 33609048
If you want to execute those php scripts, run:
$ php /path/to/file.php
0
 
LVL 3

Expert Comment

by:ssapkota
ID: 33609055
0
 
LVL 3

Expert Comment

by:ssapkota
ID: 33644777
@faithless1, Its not fair. The answer you accepted doesn't answer your question. Its just a simpler version of what you obtained yourself in #2.
My last 2 posts are directly answering your question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change password links 7 72
Form Processing in PHP 11 30
Preventing users manipulating URL strings 10 33
How do I randomize photo images before i move them to the path file? 9 20
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now