Return to the RPG Tips
Validating The Form of an Email Address
Posted to the RPG400 mailing list, http://midrange.com , by John King on 02/27/07.
P IsValidEmailFmt... P B export D IsValidEMailFmt... D PI 1N D address 1024A const varying D RegPattern S like( StdStr ) D RegString S like( StdStr ) D reg ds likeds(regex_t) D match ds likeds(regmatch_t) D buf s 80A D rc s 10I 0 /free // Regex stolen from: http://www.regular-expressions.info/email.html // Note this is "extended syntax". Basic syntax doesn't handle the + sign. // Ignoring case, it checks for: // 1) starting at the beginning of the string // 2) "one or more" from the list of [A-Z0-9._%-] // 3) an '@' sign // 4) "one or more" from the list of [A-Z0-9._%-] // 5) a "." (the . must be escaped with the \ symbol) // 6) between 2-4 characters from the list of [A-Z] // 7) at the end of the string RegPattern = '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'; rc = regcomp(reg: %trimr(RegPattern): REG_EXTENDED+REG_ICASE+REG_NOSUB); RegString = address; rc = regexec(reg: %trim(RegString): 0: match: 0); if rc = 0; return *on; else; return *off; EndIf; /end-free P IsValidEmailFmt... P E
[report a broken link by clicking here]