Error-Checking Email Addresses, for Intelligent People
May 9, 2007 Ted Holt
Note: The code accompanying this article is available for download here.
Dear Intelligent Colleague: I’ve been less than impressed with the results of keying invalid email addresses into database files, mainly because I’ve had to deal with some of that undeliverable email. I recently wrote a little RPG routine that checks for glaring errors in an email address. The people for whom I wrote it liked it and thought that you might find it helpful too. My routine enforces the following few rules: * No leading or embedded blanks. For purposes of illustration, I’m providing my routine to you as a module. If you want to use this routine, I’ll leave it to your sound judgment to determine whether you should implement it as a module, service program, or program. You’ll find three source members in the downloadable code. * Module VALIDEMAIL, the module that validates email addresses. I suggest you place the source code for the modules in file QRPGLESRC in a library of your choosing. I also suggest you put the prototype into file PROTOTYPES in the same library. Make sure that library is in your library list and run the following commands, replacing xxx with the name of your library: CRTRPGMOD MODULE(xxx/VALIDEMAIL) + SRCFILE(xxx/QRPGLESRC) + SRCMBR(VALIDEMAIL) CRTRPGMOD MODULE(xxx/VALIDEMAIT) + SRCFILE(xxx/QRPGLESRC) + SRCMBR(VALIDEMAIT) CRTPGM PGM(xxx/VALIDEMAIT) + MODULE(VALIDEMAIT VALIDEMAIL) + ACTGRP(*NEW) Call program VALIDEMAIT and look at the spool file that it generates. It lists the test email addresses in VALIDEMAIT and tells whether or not each one is valid. The VALIDEMAIL module contains one function subprocedure, cleverly named ValidateEmailAddress. This function returns zero if no errors are detected, or a positive integer that indicates the position where an error is found. Have fun, and let me know if you determine that this routine needs to be more robust.
|