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.
Email::Valid
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.
Class::CGI
param()
errors
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.
If you prefer, you can override the default error message by setting the "error" parameter in the Class::CGI::args() hash.
Class::CGI::args()
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, <ovid@cpan.org>
<ovid@cpan.org>
Please report any bugs or feature requests to bug-class-cgi-email-valid@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-CGI-Email-Valid. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-class-cgi-email-valid@rt.cpan.org
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.
To install Class::CGI::Email::Valid, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::CGI::Email::Valid
CPAN shell
perl -MCPAN -e shell install Class::CGI::Email::Valid
For more information on module installation, please visit the detailed CPAN module installation guide.