Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old December 17th, 2000, 01:03 PM
tbonds
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I'm using the below line of code in my program to check if an email address found in a FORM value is valid, yet addresses like ^someth&ing@stuff.com^ are getting through the check OK. Why might the below not be working the way I expect? I thought my code only allows "word" characters since I'm using "/w" in my pattern. Am I missing something here?
============================================
if ( $FORM{'Email'} !~ /[w-]+@[w-]+.[w-]+/ ) {
do something;
}
====================================

Thanks in advance.

-tbonds

Reply With Quote
  #2  
Old December 17th, 2000, 02:23 PM
Anonym0us Anonym0us is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 0 Anonym0us User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Forget it, even the Perl Cookbook says that there is no viable solution to this problem.

Reply With Quote
  #3  
Old December 17th, 2000, 03:00 PM
tbonds
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Maybe I can just use a for-loop and check each character for validity, besides checking something similar to ".*@*.*" for proper email construction.

If that's what it takes, then so be it.

-tbonds


Reply With Quote
  #4  
Old December 18th, 2000, 07:45 PM
Dingle Dingle is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 452 Dingle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 12 sec
Reputation Power: 8
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
sub ValidateEmail
{ # Initialize local email variable with input to subroutine. #
local $email = $_[0];

# If the e-mail address contains: #
if ($email =~ /(@.*@)|(..)|(@.)|(.@)|(^.)/ | |

# the e-mail address contains an invalid syntax. Or, if the #
# syntax does not match the following regular expression pattern #
# it fails basic syntax verification. #

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

# Basic syntax requires: one or more characters before the @ sign, #
# followed by an optional '[', then any number of letters, numbers, #
# dashes or periods (valid domain/IP characters) ending in a period #
# and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers #
# (for IP addresses). An ending bracket is also allowed as it is #
# valid syntax to have an email address like: user@[255.255.255.0] #

# Return a false value, since the e-mail address did not pass valid #
# syntax. #
return 0;
}

else {

# Return a true value, e-mail verification passed. #
return 1;
}
}

[/code]

Reply With Quote
  #5  
Old December 18th, 2000, 09:05 PM
Anonym0us Anonym0us is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 0 Anonym0us User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Instead of doing that, how about you make the user enter the valid address, a confirmation e-mail will be sent, if the user replies, then all is good and do what you want to do, if not then oh well, the user will be not signed up for whatever you are doing. This is the best approach.

Reply With Quote
  #6  
Old December 18th, 2000, 09:44 PM
tbonds
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
I agree.

I'm actually developing a shopping cart program that, among other things, emails the customer back all pertinent info regarding his order. Since most people can be careless at least some of the time, I'm adding a simple check for email validity. It won't be foolproof, but it should capture most gross mistakes.

Regards,
tbonds

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Validating email addresses using a regexp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway