We help IT Professionals succeed at work.

Limiting text box entry to an email format

Happyjack
Happyjack asked
on
203 Views
Last Modified: 2013-12-25
I have a text box input for email entry. However, the visitor can enter anything he wants and it is accepted. Is there a way to limit the entry to an email format, perhaps using the @ as a limiting character?

Here is my HTML input:
<input type="text" name="email" size="40" tabindex="4" border="0">

Here are snippets from my Perl code:
#!/usr/bin/perl -w
#Submit "Away" scores

require "cgi-lib.pl";
&ReadParse;
$mailprog = '/usr/sbin/sendmail';
print &PrintHeader;

#Check to see if any required fields are missing

#This line checks to see that all fields in form has been populated
#If any of that is true, the script will reprint the form and add error messages in all of the missing required fields.

if(($in{'number'} eq "") || ($in{'fname'} eq "") || ($in{'lname'} eq "") || ($in{'email'} eq "") || ($in{'course'} eq "") || ($in{'date'} eq "") || ($in{'slope'} eq "") || ($in{'rating'} eq "") || ($in{'adjust'} eq ""))

#Reprint the form with error messages!
..
..
..
..
<tr>
                  <td width="30%"><p>Email Address<span style="color:#990000">*</span> </p></td>
                  <td width="50%"><input type="text" name="email" size="40" tabindex="4" border="0" value = $in{'email'}></td>
                  <td width="20%"><p><div style="color:#990000; font-size:12px">
eoh

      #Write out error message if email is missing
if($in{'email'} eq "")
{print "Required field";}
print <<"eoh";
</div></p></td>
                </tr>
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ozo,
What is your code going to result in? Exactly where do I include it in my Perl script?

Thanks!
Jack
ozo's code might be place right after the
  print &PrintHeader;
line. But keep in mind that is only checks the validity of the given email address, not the length/size of other fields.
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
No, Tintin. I did not realize there was a new module. Thank you for the heads-up. I'll look it up now.
CERTIFIED EXPERT
Top Expert 2007

Commented:
When I say new, it's been around for a long time.  The CGI module has been part of the Perl core for almost 10 years now.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.