CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with match pattern

 



kencl
User

Feb 17, 2000, 2:18 PM

Post #1 of 5 (616 views)
Help with match pattern Can't Post

Trying to do a rudimentary test on a string to see if it is a valid e-mail address. It must contain a minimum of one character, then one @ sign, then at least one character, then ., then a minimum of one character. This means that it would accept a@b.c as a valid address, but not @home.com or john@work ...

Here's what I have now:

if (!$EmailAddress) {
print "Nothing Entered";
exit;
} elseif (!$NewAddress =~ m/*\@{1}*\.*/) {
print "Invalid e-mail address format";
exit;
}

Thanks.

PS - How about a UUB code for tab so we could format out code? Blockcode makes it too small.


kencl
User

Feb 17, 2000, 2:20 PM

Post #2 of 5 (616 views)
Re: Help with match pattern [In reply to] Can't Post

Code should be:

if (!$EmailAddress) {
print "Nothing Entered";
exit;
} elseif (!$EmailAddress =~ m/*\@{1}*\.*/) {
print "Invalid e-mail address format";
exit;
}


Cure
User

Feb 17, 2000, 2:39 PM

Post #3 of 5 (616 views)
Re: Help with match pattern [In reply to] Can't Post

Hi

if ($EmailAddress!~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
{
emailbad()
}


sub emailbad {
print $q->start_html(-title=>"Improper Email",
-author=>'me',
-BGCOLOR=>'white');
<CENTER><BR>

print qq~
<TABLE BORDER="0" WIDTH="400"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TDCOLSTART="1"><P><B><FONT FACE="verdana, arial, helvetica"><FONT COLOR="#000080">Status: Improper Email Address!</FONT></FONT></B></P><P><FONT SIZE=-1 FACE="verdana, arial, helvetica">You have entered an improper email address. Please make sure your email address appears in this manner: username\@domain.com, or username\@domain.net, etc. !</FONT></P>
<P><FONT SIZE="-1" FACE="verdana, arial, helvetica">If you need extra assistance, please contact us at <A HREF=""></A> for assistance.</FONT></P>
<CENTER><TABLE BORDER=0 WIDTH=400><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD COLSTART="1"><HR SIZE="1"></TD></TR</ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER>
~;
print $q->end_html;
exit;
}

Cure


japhy
Enthusiast

Feb 17, 2000, 2:58 PM

Post #4 of 5 (616 views)
Re: Help with match pattern [In reply to] Can't Post

Just so you know, if you're only looking to match a simple substring, a regular expression is overkill:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if ($name =~ /e/) { ... }
# why not use index() ?
if (index($name, 'e') != -1) { ... }
</pre><HR></BLOCKQUOTE>


kencl
User

Feb 17, 2000, 7:14 PM

Post #5 of 5 (616 views)
Re: Help with match pattern [In reply to] Can't Post

I ended up using:

($EmailAddress !~ /.+\@.+\..+/)

Took me another 20 minutes to figure out that elseif should be elsif!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives