I compiled and ran this code and didn't have any issues.
The program successfully reported PxOk=0 for a valid email address.
How did you test it?
If you tried to call the program from a command line then you are going to need to pad your email address out to 1024 characters.
I created command to trigger it so that the system could pad the field for me:
STL9110P: CMD PROMPT('Verify Email')
PARM KWD(EMAIL) TYPE(*CHAR) LEN(1024) PROMPT('Email' 1) DFT(' ')
PARM KWD(RTN) TYPE(*CHAR) LEN(1) +
PROMPT('Not Valid(1) Valid(0)' 2) DFT(' ')
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Danny Rodius
Sent: Tuesday, December 5, 2017 5:20 AM
To: RPG400-L@xxxxxxxxxxxx
Subject: Using regex()
Hi,
Trying to use regex() and base my pgm on the example found in the redbook "Who Knew You Could Do That
with RPG IV"
I checked already the used pattern in some different checkers found on the web and the all came up to check almost every email.
However when using in my program it seems allways to retuen that the email address provided is wrong, even with a valid one.
Hereby my source:
ctl-opt main(main) dftactgrp(*no);
/copy cregexpr
// Main routine
dcl-proc main;
dcl-pi main extpgm('STL9110P');
PxEMail char(1024);
PxOK int(10);
end-pi;
dcl-c RegPattern '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
dcl-s RegString varchar(1024);
dcl-ds reg likeds(C_regex_t);
dcl-ds pmatch likeds(C_regmatch_t) dim(1);
dcl-s rc int(10) inz(9);
dcl-s cflags int(10);
cflags = REG_EXTENDED + REG_ICASE + REG_NOSUB;
if (regcomp(reg: RegPattern: cflags) = 0);
RegString = %trim(PxEMail);
rc = regexec(reg: RegString: %elem(pmatch): pmatch: 0);
if rc = 0;
PxOK = 0;
else;
PxOK = 1;
EndIf;
endif;
regfree(reg);
end-proc;
My hope that there is someone here who could point me out what I'm doing wrong.
Regards,
Danny
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=GYVfe7k5MogwSsRr94zbPeTDRJYpFK3WOG9BKFEwK1s&m=z4pKSIdyzitoblEMzFukBcaBewcphVJ-xPB546bkE1w&s=nT4t4ALMdWs0QP43Tyx4VDa2SKopSfZe2EYYAITIu-Q&e=
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_rpg400-2Dl&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=GYVfe7k5MogwSsRr94zbPeTDRJYpFK3WOG9BKFEwK1s&m=z4pKSIdyzitoblEMzFukBcaBewcphVJ-xPB546bkE1w&s=DtWMiCVr-xQP3Ao1RQm2rm_4ztuEjFD81j3XRDW3OLA&e=.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://urldefense.proofpoint.com/v2/url?u=http-3A__amzn.to_2dEadiD&d=DwICAg&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=GYVfe7k5MogwSsRr94zbPeTDRJYpFK3WOG9BKFEwK1s&m=z4pKSIdyzitoblEMzFukBcaBewcphVJ-xPB546bkE1w&s=ylNnjKf0wENrfawMsVA1dSAoWyckmqFrcsTN_dpycz4&e=
As an Amazon Associate we earn from qualifying purchases.