I've only been using Perl for about a week now, so this question is quite simple!
Basically I am trying to write a CGI script that can verify whether an email address is valid (eg. contains one and only one @ symbol, has no invalid characters such as ; : , / etc) for use with sendmail. Has anyone written anything similar or have any ideas how I could write this?
I have tried playing around with the index and substr functions but haven't really gotten anywhere...
Comments
:
: Basically I am trying to write a CGI script that can verify whether an email address is valid (eg. contains one and only one @ symbol, has no invalid characters such as ; : , / etc) for use with sendmail. Has anyone written anything similar or have any ideas how I could write this?
:
: I have tried playing around with the index and substr functions but haven't really gotten anywhere...
:
try this:
#perl
$_ = "me@xxxx.com";
if( tr/@/@/ == 1 && !/[,;:/]/ ) {
print "ok
";
} else {
print "not ok
";
}
unless($email_string =~ /.+@.+..+/)
{
#Notify of email error
}
Then go get a Perl book and look up regular expressions, you will find all you need to make that statement much better and you will find alot of other things you may not know about string manipulation with Perl(like substitution, translation, and pattern matching).
sorry for the double post mr.boardmanager