Newbie question!

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

  • : 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...
    :

    try this:
    #perl

    $_ = "me@xxxx.com";

    if( tr/@/@/ == 1 && !/[,;:/]/ ) {
    print "ok
    ";
    } else {
    print "not ok
    ";
    }


  • sheesh...or try this.... /.+@.+..+/

    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).
  • so theres no confusion, my last post was meant for del not mheeter.

    sorry for the double post mr.boardmanager
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories