Solved

Validating user's email address input from form

Posted on 1997-11-27
5
141 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

785 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