?
Solved

Email Validation Help with command line usage in Ubuntu

Posted on 2010-09-05
8
Medium Priority
?
1,033 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:faithless1
ID: 33608167
Thanks for the responses.

- Ray, how would I run this script on the command line in unix?
0
 
LVL 111

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

762 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