View on
Curtis "Ovid" Poe > Class-CGI-Email-Valid-0.01 > Class::CGI::Email::Valid



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.01   Source  


Class::CGI::Email::Valid - Validate email from forms


Version 0.01


 use Class::CGI handlers => {
     email => 'Class::CGI::Email::Valid',
 my $cgi = Class::CGI->new;
 my $email = $cgi->param('email');

 if ( my %error_for = $cgi->errors ) {
      if ( $error_for{email} ) {


Normally we fetch email from forms, run it through Email::Valid or something similar, untaint it, if necessary, and save it somewhere. This class handles the email validation via Email::Valid and optionally handles untainting.

Unlike other Class::CGI handlers, this handler returns the email address unchanged; the param() method does not return an object. If the email address failed to validate, the error message will be in the error hash returned by the errors method. As usual, the error key will be the name of the param used.

Basic usage ^

 use Class::CGI handlers => {
     email_address => 'Class::CGI::Email::Valid',
 my $cgi   = Class::CGI->new;
 my $email = $cgi->param('email_address');

Any parameter name may be validated as an email address. If the value of the parameter does not appear to be a valid email address, the value entered will still be returned! This makes it easy to create "sticky" forms.


This handler does not provide any untainting facilities. It merely checks that the email address entered validated with Email::Valid. This is because email addresses often get used in the shell and it is very difficult to ensure that the full range of email addresses allowed are safe for such use. It is the responsibility of the programmer to ensure that a valid email address is safe for such use.

Overridding the error message

If you prefer, you can override the default error message by setting the "error" parameter in the Class::CGI::args() hash.

 use Class::CGI handlers => {
     email => 'Class::CGI::Email::Valid',
 my $cgi   = Class::CGI->new;
 $cgi->args( email => { error => "You gave me a bad email address, dummy!" } );
 my $email = $cgi->param('email');


Curtis "Ovid" Poe, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



Copyright 2006 Curtis "Ovid" Poe, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: