Solved

Validating user's email address input from form

Posted on 1997-11-27
5
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

632 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