×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




You can use the regex APIs to do this. The data structure for the APIs are in QSYSINC.

D pattern S 512A varying
D reg DS likeds(regex_t)
D match DS likeds(regmatch_t)
D rc S 10I 0
D NULL C CONST(x'00')

//---------------------
// cflags for regcomp()
//---------------------

D REG_BASIC C CONST(0)
D REG_EXTENDED C CONST(1)
D REG_ICASE C CONST(2)
D REG_NEWLINE C CONST(4)
D REG_NOSUB C CONST(8)

//---------------------
// eflags for regexec()
//---------------------

D REG_NOTBOL C CONST(256)
D REG_NOTEOL C CONST(512)

//-----------------------------------
// errors returned by the C functions
//-----------------------------------

D REG_NOMATCH C CONST(1)
D REG_BADPAT C CONST(2)
D REG_ECOLLATE C CONST(3)
D REG_ECTYPE C CONST(4)
D REG_EESCAPE C CONST(5)
D REG_ESUBREG C CONST(6)
D REG_EBRACK C CONST(7)
D REG_EPAREN C CONST(8)
D REG_EBRACE C CONST(9)
D REG_BADBR C CONST(10)
D REG_ERANGE C CONST(11)
D REG_ESPACE C CONST(12)
D REG_BADRPT C CONST(13
D REG_ECHAR C CONST(14
D REG_EBOL C CONST(15
D REG_EEOL C CONST(16
D REG_ECOMP C CONST(17
D REG_EEXEC C CONST(18

//------------------------------------------------------------
// Structure of a compiled regular expression:
//
// #define __REG_SUBEXP_MAX 9
// typedef struct {
// size_t re_nsub;
// void *re_comp;
// int re_cflags;
// size_t re_erroff;
// size_t re_len;
// _LC_colval_t re_ucoll[2];
// void *re_lsub[__REG_SUBEXP_MAX+1];
// void *re_esub[__REG_SUBEXP_MAX+1];
// unsigned char re_map[256];
// mbstate_t re_shift;
// short re_dbcs;
// } regex_t;
//------------------------------------------------------------

D REG_SUBEXP_MAX C 10

D regex_t DS qualified
D align based(prototype_only)
D re_nsub 10I 0
D re_comp *
D re_cflags 10I 0
D re_erroff 10I 0
D re_len 10I 0
D re_ucoll 10I 0 dim(2)
D re_lsub * DIM(REG_SUBEXP_MAX)
D re_esub * DIM(REG_SUBEXP_MAX)
D re_map 256A
D re_shift 5I 0
D re_dbcs 5I 0

//------------------------------------------------------------
// structure used to report matches found by regexec()
//
// typedef struct {
// _off_t rm_so; /* offset of substring
// mbstate_t rm_ss; /* shift state at start of subst
// _off_t rm_eo; /* offset of next char after subst
// mbstate_t rm_es; /* shift state at end of subst
// } regmatch_t;
//
// NOTE: It's important to remember that C starts numbering
// string positions with '0' and RPG starts with '1'.
// Thus, rm_so+1 is the first char in substring, rm_eo is
// the last char in the substring in RPG.
//------------------------------------------------------------

D regmatch_t DS qualified
D align based(prototype_only)
D rm_so 10I 0
D rm_ss 5I 0
D rm_eo 10I 0
D rm_es 5I 0



// regcomp() -- Compile a Regular Expression ("RE")

D regcomp PR 10I 0 extproc('regcomp')
D preg like(regex_t)
D pattern * value options(*string)
D cflags 10I 0 value

// regexec() -- Execute a compiled Regular Expression ("RE")

D regexec PR 10I 0 extproc('regexec')
D preg like(regex_t) const
D string * value options(*string)
D nmatch 10U 0 value
D pmatch like(regmatch_t) dim(100)
D options(*varsize)
D eflags 10I 0 value

// regerror() -- Return error information from regcomp/regexec

D regerror PR 10U 0 extproc('regerror')
D errcode 10I 0 value
D preg like(regex_t) const
D errbuf * value
D errbuf_size 10I 0 value

// regfree() -- free memory locked by Regular Expression

D regfree PR extproc('regfree')
D preg like(regex_t)

/FREE

//-----------------------------------------------------
// Set pattern to match
//
// Note: The pattern must be null (x'00') terminated
//
// For more info about this E-mail address expresion
// see: http://www.regular-expressions.info/email.html
//-----------------------------------------------------

pattern = '^[a-zA-Z0-9' + '&''' + '._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z<mailto:+@[a-zA-Z0-9.-]+\.[a-zA-Z>]' +
'{2,6}$' + NULL;

//-------------------------------
// Compile the regular expression
//-------------------------------

rc = regcomp( reg : Pattern : REG_EXTENDED + REG_ICASE + REG_NOSUB );

if rc <> 0; // An error occurred
regerror(rc: reg: %addr(Buf): %size(buf)); // so get the error
endif;

//--------------------------------------------------------
// Check the e-mail address against the regular expression
//--------------------------------------------------------

rc = regexec( reg : %trim(emailAddress) : 0 : match : 0 );

if rc <> 0; // An error occurred
regerror(rc: reg: %addr(Buf): %size(buf)); // so get the error
endif;

//--------------
//End processing
//--------------
// Clean up everything
regfree(reg);



-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Vinay Gavankar
Sent: Tuesday, October 14, 2014 11:27 AM
To: Midrange Systems Technical Discussion
Subject: Syntax check a string as a valid email address

Is there an API or a service program I can use to check just the syntax of a string to be a valid email address?

I saw TAATOOL command CHKMAILADR, but my client tries to avoid using TAATOOL if possible (not sure of the reasons behind it).

TIA

Vinay
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx<mailto:MIDRANGE-L@xxxxxxxxxxxx> To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx<mailto:MIDRANGE-L-request@xxxxxxxxxxxx> Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.