Hi, I've been tinkering with this for about an hour now trying to figure out why it won't catch intentional mistakes that I throw in. What I'm doing is trying to validate an email address, with something like this:
if ($MailTo !~ /\@*\./) { #set a kill flag #print a message }
So, to clear up the seemingly random characters up there, that's a / to open it, and escaped @ sign, a *, an escaped ., then another / to close it. Essentially I'm looking for an @ sign then a dot. On the console, this line works great, catches mistakes and everything. But when I run it through a web page as a CGI script it doesn't catch it unless I don't put anything in the field. Any ideas? Here's all of the code, just to see if anybody catches a minor mistake in my code:
use Net::SMTP; use CGI ':standard'; #Get parameters from http string# my $ServerName = param('server'); my $MailFrom = param('from'); my $MailTo = param('to'); my $Subject = param('subject'); my $Content = param('content'); print "Content-type: text/html\n\n"; print "<html>\n <head>\n <title>Mail Results</title>\n </head>\n <body>\n"; my $kill = 0; if (!($MailFrom =~/\@*\./)) { $kill = 1; print "Invalid return address in From box. "; } if (!($MailTo !~/\@*\./)) { $kill = 1; print "Invalid destination address. Please notify the webmaster o +f this problem by sending an email to wvhs-web\@charter.net. "; } if ($kill == 1) { die("One or more errors have occurred which prevent the script fro +m continuing further. "); } else { $smtp = Net::SMTP->new($ServerName, Debug => 0); die "Couldn't connet to server: $!" unless $smtp; $smtp->mail($MailFrom); $smtp->to($MailTo); $smtp->data(); $smtp->datasend("To: $MailTo\n"); $smtp->datasend("From: $MailFrom\n"); $smtp->datasend("Subject: $Subject\n"); $smtp->datasend("\n"); $smtp->datasend("$Content\n\n"); $smtp->dataend(); $smtp->quit(); print "Mail Sent Successfully\n \n"; } print "</body>\n </html>";
Thanks, Eric

edited by ybiC: Balanced <code> and <readmore> tags, retitle from "Regex problem"


In reply to email address validation regexp by wallyweezle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.