Monday, November 8, 2009
To R:BASE Community,
Here is a tip from the Father of R:BASE, Wayne Erickson (Head of the
R:BASE Development Team),
that validates the syntax for an email address in R:BASE.
Wayne's Corner:
Validating syntax for an email address in R:BASE ...
For an example, assume you have a table called "person" and it has a
column called "email"
for storing email addresses. You want to check some things to make
sure the values in this
column meets some basic things an email address should have. Here is
the rule definition code:
Rules 'Improper Email Address' FOR Person SUCCEED +
WHERE +
(SLOC(SMOVE(`Email`,(SLOC(`Email`,'@')+1),SLEN(`Email`)-(SLOC(`Email`,'@')),'
',1),'.')) > 1 +
AND +
((slen(SMOVE(`email`,(SLOC(`Email`,'@')+1),(SLEN(`Email`)-SLOC(`Email`,'@')),'
',1)))- +
(sloc(SMOVE(`email`,(SLOC(`Email`,'@')+1),(SLEN(`Email`)-SLOC(`Email`,'@')),'
',1),'.'))) >= 2 +
AND +
(SLOC(STRIM(LJS(`Email`,40)),'@')) > 2
This particular rule checks three things:
1. Are there at least 2 characters before an "@" character? This is
done with the
(SLOC(STRIM(LJS(`Email`,40)),'@')) > 2 part of the rule.
2. Is there a "." after the "@"and is there at least one character
between the "@"
and the "."? This is done with the (
SLOC(SMOVE(`Email`,(SLOC(`Email`,'@')+1),SLEN(`Email`)-(SLOC(`Email`,'@')),'
',1),'.')) > 1 part of the rule.
3. Are there at least 2 characters after the "." which follows the
"@" character?
This would allow something like [email protected] but not [email protected]. This is
done with the
((slen(SMOVE(`email`,(SLOC(`Email`,'@')+1),(SLEN(`Email`)-SLOC(`Email`,'@')),'
',1)))- +
(sloc(SMOVE(`email`,(SLOC(`Email`,'@')+1),(SLEN(`Email`)-SLOC(`Email`,'@')),'
',1),'.'))) >= 2 part of the rule.
Have fun implementing this cool code in your R:BASE applications!
Very Best R:egards,
Razzak.