Solved

Validating user's email address input from form

Posted on 1997-11-27
5
142 Views
Last Modified: 2013-12-25
#2: How can I detect if an email address entered on a form contains a "@" symbol, and at least one period "."?  I am trying to perform an error check on the input.  I know a little CGI scripting, so I am not asking for a complete script...just a "if...then" snippet would do fine.
0
Comment
Question by:Kapusta
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1831468
Which language please?
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1831469
Ok, its Perl.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831470
If you are talking perl -

if ($email =~ /\@.+\./ {
# "good"
} else {
# "bad"
}

That does what you ask - checks for a @ and a . after the @, but that really doesn't validate the email address. Look at http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_check_a_valid_email_ad for a discussion and a pointer to a script that will do a better job.

If this answers your question, let me know and I will repost it as an answer. Good luck!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831471
oops, that line was supposed to be

if ($email =~ /\@.+\./) {

(forgot a ")")
0
 
LVL 6

Accepted Solution

by:
alamo earned 70 total points
ID: 1831472
Just to restate this as an answer, the following does what you asked for.

if ($email =~ /\@.+\./) {
 # "good"
} else {
 # "bad"
}

But see http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_check_a_valid_email_ad for info on why this might not be what you really want to do.

good luck!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question