Solved

Validating user's email address input from form

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now