Validating email addresses within forms

I'm starting to work on developing an AJAX-style checkout process and came across something pretty cool. It uses a combination of a server-side Perl script, a Perl module, some JavaScript and a simple HTML form.

The first thing I had to do was install the Mail::CheckUser module. The installation on all 5 servers I tried it on didn't want to work via normal methods, and 'make test' always came back saying it had errors, but doing a 'make install' let it install and it works just fine, even with all of the errors reported by the test step.

The next thing to do was create a real simple Perl script to check it out. I simply called it validate.pl (since it's part of a form validation routine) and loaded it to a web server with the correct permissions, then replicated it across the rest of our servers. The actual work is done by the following chunk of code.
#!/usr/bin/perl
print qq(Content-type: text/plain\n\n);
use CGI qw (:standard);
checkEmail();
exit;

sub checkEmail{
use Mail::CheckUser;
my $email = param('arg');
my $ok = Mail::CheckUser::check_email($email);
if ($ok) { print qq(emailMessage\|Email appears valid); }
else { print qq(emailMessage\|<span style="color: rgb(255, 0, 0);">Invalid email address</span>); }
}
So now that I have a Perl script using a module, I needed some JavaScript to do some of the validation. I borrowed a script from this page to do most of the heavy lifting. This allowed me to create a simple HTML form that allows entry of an email address, then it checks that email address when the user moves away from the text box.

Sure, it's not rocket science. But who says web programming should be?

Comments

Popular posts from this blog

Yii multiple select dropdownlist with default values

May 2021 updates

Been getting busy