Claus Derlien wrote:
>...i need a neat way to validate an email adress, so i
> can return an error if it contains any illegal chars...

Can U2 use Regular Expressions (RegExp)?

As mentioned, there are many RFC rules that must be met in order for an
e-mail address to be considered valid.  I found a nice regular expression
that seems to check many of them.  In order to execute regular expressions
I'll wrap them in a little Perl script and then call them from MV code.
This can be done for a LOT of functions so that we don't feel compelled to
write MV BASIC functions when there are perfectly good routines available
in open source.

Here's the code, save as mailok.pl in Windows or *nix:
----------
#!/usr/local/bin/perl
# Change above line in *nix as required
my $email = $ARGV[0];
my $mask = '^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)';
$mask .= '*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$';
# mask broken into two lines just to avoid wrapping when printed
if ($email =~ $mask) {
        print "OK $1 $2 $3";
} else {
        print "NO";
}
----------

To call it from BASIC: 
ADDR = "[EMAIL PROTECTED]" ; * must be in lowercase
CMD =  'mailok.pl ':ADDR
RESULT = UVRunCommand(CMD)

Or for *nix, use PERFORM CMD CAPTURING RESULT
(Or EXECUTE depending on your MV flavor, etc)
I don't want to get into how to configure Perl, this is on using Perl from
BASIC, but depending on how you have Perl setup, and your OS, you may need
CMD to be something like:
CMD = 'c:\perl\perl.exe mailok.pl ':ADDR
Or for *nix:
CMD = 'perl /var/lib/myperlstuff/mailok.pl ':ADDR

RESULT now has 1 field if it was bad or 4 space-delimited fields if it was
OK.
Param1 = NO if it was a bad address or OK if it was good.
Param2 is the part before the "@".
Param3 is the domain without the TLD (the part before the period).
Param4 is the TLD (Top Level Domain, COM, TV, MY, NAME, GOV, EDU, etc).
These params are provided simply to be informational.

Why use Perl for a little ditty like this?
- If you improve the script then no BASIC code changes are required, your
application improves without a recompile.
- The exact same routine can be used for your website, or from other
programs on your system.
- The same code can be used with any MV flavor.  It's a shame when good MV
algorithms have to be re-written just because of syntax issues.

HTH
Tony Gravagno
Nebula Research and Development
TG@ removethisNebula-RnD
.com 
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to