Discussion:
Syntax check a string as a valid email address
(too old to reply)
Vinay Gavankar
2014-10-14 18:27:02 UTC
Permalink
Raw Message
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-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Mark S Waterbury
2014-10-14 18:49:59 UTC
Permalink
Raw Message
See:
http://iprodeveloper.com/systems-management/how-validate-e-mail-addresses

(NOTE: you may need to "sign-up" to view the contents of this site, but
it is free to do so.)
Post by Vinay Gavankar
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-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Monnier, Gary
2014-10-14 19:07:03 UTC
Permalink
Raw Message
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-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] 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-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org<mailto:MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org> To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org<mailto:MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org> Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Barbara Morris
2014-10-14 23:31:33 UTC
Permalink
Raw Message
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure
exactly the same as the C struct. The C data structure's length is a
multiple of its alignment, which is 16 since it contains a pointer. The
RPG data structure doesn't have the extra padding at the end, so it's
smaller than the C struct. The regex functions expect the full length,
and if the additional storage happens to be storage that your program is
using, you can get unexpected results from the regex functions and/or
from using your fields that happen to be where the regex functions think
the end of the struct is.

You could explicitly set the length of the regex_t structure to 640.

Or if you don't want to hard-code the length ...

You could code DIM(1) to get the RPG compiler to define the size of
regex_t as a multiple of its alignmen.

D reg DS likeds(regex_t) dim(1)

And then you'd pass reg(1) instead of reg when you do the call.

Or, since you're not actually using the subfields of regex_t, you could
keep the calls simple by renaming your regex_t to regex_sub_t and then
defining regex_t like this:

D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)
--
Barbara
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Scott Klement
2014-10-15 02:03:56 UTC
Permalink
Raw Message
In addition to the error that Barbara points out here....

All of the fields that are size_t in C should be 10u 0 in RPG. (size_t
in C is unsigned. ssize_t would be signed... but is not used here.)
Post by Barbara Morris
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure
exactly the same as the C struct. The C data structure's length is a
multiple of its alignment, which is 16 since it contains a pointer. The
RPG data structure doesn't have the extra padding at the end, so it's
smaller than the C struct. The regex functions expect the full length,
and if the additional storage happens to be storage that your program is
using, you can get unexpected results from the regex functions and/or
from using your fields that happen to be where the regex functions think
the end of the struct is.
You could explicitly set the length of the regex_t structure to 640.
Or if you don't want to hard-code the length ...
You could code DIM(1) to get the RPG compiler to define the size of
regex_t as a multiple of its alignmen.
D reg DS likeds(regex_t) dim(1)
And then you'd pass reg(1) instead of reg when you do the call.
Or, since you're not actually using the subfields of regex_t, you could
keep the calls simple by renaming your regex_t to regex_sub_t and then
D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Scott Klement
2014-10-15 02:07:45 UTC
Permalink
Raw Message
Also, just FYI... I made this same mistake at some point in the past.
If you got the bad code from me, I apologize. :-)
Post by Scott Klement
In addition to the error that Barbara points out here....
All of the fields that are size_t in C should be 10u 0 in RPG. (size_t
in C is unsigned. ssize_t would be signed... but is not used here.)
Post by Barbara Morris
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure
exactly the same as the C struct. The C data structure's length is a
multiple of its alignment, which is 16 since it contains a pointer. The
RPG data structure doesn't have the extra padding at the end, so it's
smaller than the C struct. The regex functions expect the full length,
and if the additional storage happens to be storage that your program is
using, you can get unexpected results from the regex functions and/or
from using your fields that happen to be where the regex functions think
the end of the struct is.
You could explicitly set the length of the regex_t structure to 640.
Or if you don't want to hard-code the length ...
You could code DIM(1) to get the RPG compiler to define the size of
regex_t as a multiple of its alignmen.
D reg DS likeds(regex_t) dim(1)
And then you'd pass reg(1) instead of reg when you do the call.
Or, since you're not actually using the subfields of regex_t, you could
keep the calls simple by renaming your regex_t to regex_sub_t and then
D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Monnier, Gary
2014-10-15 17:47:11 UTC
Permalink
Raw Message
Thank you Barbara and Scott for pointing out the errors you found. The program using the regex structures has been running just fine for about 5 years.

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of Barbara Morris
Sent: Tuesday, October 14, 2014 4:32 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure exactly the same as the C struct. The C data structure's length is a multiple of its alignment, which is 16 since it contains a pointer. The RPG data structure doesn't have the extra padding at the end, so it's smaller than the C struct. The regex functions expect the full length, and if the additional storage happens to be storage that your program is using, you can get unexpected results from the regex functions and/or from using your fields that happen to be where the regex functions think the end of the struct is.

You could explicitly set the length of the regex_t structure to 640.

Or if you don't want to hard-code the length ...

You could code DIM(1) to get the RPG compiler to define the size of regex_t as a multiple of its alignmen.

D reg DS likeds(regex_t) dim(1)

And then you'd pass reg(1) instead of reg when you do the call.

Or, since you're not actually using the subfields of regex_t, you could keep the calls simple by renaming your regex_t to regex_sub_t and then defining regex_t like this:

D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)

--
Barbara

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Scott Klement
2014-10-15 17:51:03 UTC
Permalink
Raw Message
It's probably working fine because you don't use any of the subfields of
the regex_t data structure, right?

One of the dangers of sharing your code (one that I know only too well!)
is that if you make any mistakes, it's out there for the whole world to
see and point out :-)

Anyway, if you want, I do have the definitions posted here:
http://www.scottklement.com/rpg/copybooks/regex_h.rpgle.txt

-SK
Post by Monnier, Gary
Thank you Barbara and Scott for pointing out the errors you found. The program using the regex structures has been running just fine for about 5 years.
-----Original Message-----
Sent: Tuesday, October 14, 2014 4:32 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure exactly the same as the C struct. The C data structure's length is a multiple of its alignment, which is 16 since it contains a pointer. The RPG data structure doesn't have the extra padding at the end, so it's smaller than the C struct. The regex functions expect the full length, and if the additional storage happens to be storage that your program is using, you can get unexpected results from the regex functions and/or from using your fields that happen to be where the regex functions think the end of the struct is.
You could explicitly set the length of the regex_t structure to 640.
Or if you don't want to hard-code the length ...
You could code DIM(1) to get the RPG compiler to define the size of regex_t as a multiple of its alignmen.
D reg DS likeds(regex_t) dim(1)
And then you'd pass reg(1) instead of reg when you do the call.
D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)
--
Barbara
--
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Monnier, Gary
2014-10-15 18:12:27 UTC
Permalink
Raw Message
Thank you Scott.

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of Scott Klement
Sent: Wednesday, October 15, 2014 10:51 AM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address

It's probably working fine because you don't use any of the subfields of
the regex_t data structure, right?

One of the dangers of sharing your code (one that I know only too well!)
is that if you make any mistakes, it's out there for the whole world to
see and point out :-)

Anyway, if you want, I do have the definitions posted here:
http://www.scottklement.com/rpg/copybooks/regex_h.rpgle.txt

-SK
Post by Monnier, Gary
Thank you Barbara and Scott for pointing out the errors you found. The program using the regex structures has been running just fine for about 5 years.
-----Original Message-----
Sent: Tuesday, October 14, 2014 4:32 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Monnier, Gary
D regex_t DS qualified
D align based(prototype_only)
Unfortunately, RPG's ALIGN keyword doesn't make the data structure exactly the same as the C struct. The C data structure's length is a multiple of its alignment, which is 16 since it contains a pointer. The RPG data structure doesn't have the extra padding at the end, so it's smaller than the C struct. The regex functions expect the full length, and if the additional storage happens to be storage that your program is using, you can get unexpected results from the regex functions and/or from using your fields that happen to be where the regex functions think the end of the struct is.
You could explicitly set the length of the regex_t structure to 640.
Or if you don't want to hard-code the length ...
You could code DIM(1) to get the RPG compiler to define the size of regex_t as a multiple of its alignmen.
D reg DS likeds(regex_t) dim(1)
And then you'd pass reg(1) instead of reg when you do the call.
D regex_t DS qualified
D align based(prototype_only)
D reg likeds(regex_sub_t) dim(1)
--
Barbara
--
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
John Yeung
2014-10-14 23:46:00 UTC
Permalink
Raw Message
Post by Vinay Gavankar
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?
While regex is a very nice tool to have in the toolbox, if it's not
already in the toolbox, this is a task that, in my opinion, is not bad
just using RPG's BIFs. I guess it might depend on precisely what you
want to accept as "valid syntax" of an e-mail address, but for basic
"eyeball" tests, %SCAN goes a long way. Maybe throw in %CHECK if
you're so inclined.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Mike Cunningham
2014-10-15 13:17:28 UTC
Permalink
Raw Message
This is RPG to try and catch the types of errors we have seen. It was written about 5 years ago so could probably use a refresh to use some new bifs, but it works for us. It is in a callable app that accepts the email and sends back the vaild and error values

C Test BEGSR
C EVAL Valid = 'Y'
C EVAL Error = *BLANK

C* must not be all blanks
C IF Email = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'E-mail is blank'
C LEAVESR
C ENDIF
C* must contain at least one '@' sign
C EVAL sPos = %scan('@':Email)
C EVAL @Pos = sPos
C IF sPos = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required @ sign'
C LEAVESR
C ENDIF
C* error if contains more that one '@' sign
C IF %scan('@':Email:Spos+1) > 0
C EVAL Valid = 'N'
C EVAL Error = 'More than one @ sign'
C LEAVESR
C ENDIF
C* must contain at least one '.' sign after the first '@' sign
C IF %scan('.':Email:Spos+1) = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required . (period)'
C LEAVESR
C ENDIF
C* error if contains a blank
C IF %scan(' ':%trim(Email)) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an embedded blank'
C LEAVESR
C ENDIF
C* split address into left and right sides
C EVAL LeftSide = %subst(Email:1:@pos-1)
C EVAL RightSide = %subst(Email:@pos+1)
C* left address may not be blank
C IF LeftSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Left side address missing'
C LEAVESR
C ENDIF
C* left address may not start with a '.'
C IF %scan('.':LeftSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not end with a '.'
C IF %subst(LeftSide:%len(%trim(LeftSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not have a double '.'
C IF %scan('..':LeftSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* check for left-side valid characters
C EVAL sPos = %check(CheckLeft:LeftSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' + %trim(%editc(sPos:'4'))
C LEAVESR
C ENDIF
C* right address may not be blank
C IF RightSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Right side address missing'
C LEAVESR
C ENDIF
C* right address may not start with a '.'
C IF %scan('.':RightSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not end with a '.'
C IF %subst(RightSide:%len(%trim(RightSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not have a double '.'
C IF %scan('..':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* right address may not have a '.-' string
C IF %scan('.-':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a +
C . (period) - (dash) string'
C LEAVESR
C ENDIF
C* check for right-side valid characters
C EVAL sPos = %check(CheckRight:RightSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' +
C %trim(%editc(sPos+@pos:'4'))
C LEAVESR
C ENDIF
C ENDSR

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of John Yeung
Sent: Tuesday, October 14, 2014 7:46 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Vinay Gavankar
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?
While regex is a very nice tool to have in the toolbox, if it's not already in the toolbox, this is a task that, in my opinion, is not bad just using RPG's BIFs. I guess it might depend on precisely what you want to accept as "valid syntax" of an e-mail address, but for basic "eyeball" tests, %SCAN goes a long way. Maybe throw in %CHECK if you're so inclined.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
r***@public.gmane.org
2014-10-15 13:32:15 UTC
Permalink
Raw Message
Thank you for sharing that Mike.
Yes, it could use some updating. But I'm not saying that just because I'm
encouraging the latest and greatest.
Some of us are curious as to what you mean by
* check for left-side valid characters
C EVAL sPos = %check(CheckLeft:LeftSide)
Like what is the value of CheckLeft?
Modernizing this by making it a subprocedure instead of a subroutine, and
putting LeftSide as a variable local to that subprocedure would make it
tighter and easier to post.
Then once you have it as a subprocedure it's quite easy to put into a
service program.
Once you have it into a service program it's quite easy to make a UDF, or
User Defined Function, out of it so you can do stuff like
select PrimaryKey, SomeDescriptiveColumn, EmailAddress
from tableInQuestion
where VerifyEmail(EmailAddress)='N'

Where VerifyEmail is the results of your evolution from subroutine to
internal subprocedure to service program subprocedure to user defined
function.

And none of this was just style for style's sake. I even left out the
whole fixed format vs free format argument.

Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: Mike Cunningham <mike.cunningham-***@public.gmane.org>
To: Midrange Systems Technical Discussion <midrange-l-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org>
Date: 10/15/2014 09:17 AM
Subject: RE: Syntax check a string as a valid email address
Sent by: "MIDRANGE-L" <midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org>



This is RPG to try and catch the types of errors we have seen. It was
written about 5 years ago so could probably use a refresh to use some new
bifs, but it works for us. It is in a callable app that accepts the email
and sends back the vaild and error values

C Test BEGSR
C EVAL Valid = 'Y'
C EVAL Error = *BLANK

C* must not be all blanks
C IF Email = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'E-mail is blank'
C LEAVESR
C ENDIF
C* must contain at least one '@' sign
C EVAL sPos = %scan('@':Email)
C EVAL @Pos = sPos
C IF sPos = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required @ sign'
C LEAVESR
C ENDIF
C* error if contains more that one '@' sign
C IF %scan('@':Email:Spos+1) > 0
C EVAL Valid = 'N'
C EVAL Error = 'More than one @ sign'
C LEAVESR
C ENDIF
C* must contain at least one '.' sign after the first '@' sign
C IF %scan('.':Email:Spos+1) = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required . (period)'
C LEAVESR
C ENDIF
C* error if contains a blank
C IF %scan(' ':%trim(Email)) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an embedded blank'
C LEAVESR
C ENDIF
C* split address into left and right sides
C EVAL LeftSide = %subst(Email:1:@pos-1)
C EVAL RightSide = %subst(Email:@pos+1)
C* left address may not be blank
C IF LeftSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Left side address missing'
C LEAVESR
C ENDIF
C* left address may not start with a '.'
C IF %scan('.':LeftSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not end with a '.'
C IF %subst(LeftSide:%len(%trim(LeftSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not have a double '.'
C IF %scan('..':LeftSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* check for left-side valid characters
C EVAL sPos = %check(CheckLeft:LeftSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' +
%trim(%editc(sPos:'4'))
C LEAVESR
C ENDIF
C* right address may not be blank
C IF RightSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Right side address missing'
C LEAVESR
C ENDIF
C* right address may not start with a '.'
C IF %scan('.':RightSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not end with a '.'
C IF %subst(RightSide:%len(%trim(RightSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not have a double '.'
C IF %scan('..':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* right address may not have a '.-' string
C IF %scan('.-':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a +
C . (period) - (dash) string'
C LEAVESR
C ENDIF
C* check for right-side valid characters
C EVAL sPos = %check(CheckRight:RightSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' +
C %trim(%editc(sPos+@pos:'4'))
C LEAVESR
C ENDIF
C ENDSR

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of
John Yeung
Sent: Tuesday, October 14, 2014 7:46 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Vinay Gavankar
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?
While regex is a very nice tool to have in the toolbox, if it's not
already in the toolbox, this is a task that, in my opinion, is not bad
just using RPG's BIFs. I guess it might depend on precisely what you want
to accept as "valid syntax" of an e-mail address, but for basic "eyeball"
tests, %SCAN goes a long way. Maybe throw in %CHECK if you're so
inclined.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Mike Cunningham
2014-10-15 13:56:17 UTC
Permalink
Raw Message
I guess that would help :)

D CheckLeft C '!#$%&''*+-/=?^_`{|}~.abcdefghijklmn-
D opqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW-
D XYZ1234567890'
D CheckRight C '-.abcdefghijklmnopqrstuvwxyzABCDEFG-
D HIJKLMNOPQRSTUVWXYZ1234567890'

This code would be much easier to read in free format

I do have it setup as a stored procedure for use from java apps :)


-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of rob-***@public.gmane.org
Sent: Wednesday, October 15, 2014 9:32 AM
To: Midrange Systems Technical Discussion
Subject: RE: Syntax check a string as a valid email address

Thank you for sharing that Mike.
Yes, it could use some updating. But I'm not saying that just because I'm encouraging the latest and greatest.
Some of us are curious as to what you mean by
* check for left-side valid characters
C EVAL sPos = %check(CheckLeft:LeftSide)
Like what is the value of CheckLeft?
Modernizing this by making it a subprocedure instead of a subroutine, and putting LeftSide as a variable local to that subprocedure would make it tighter and easier to post.
Then once you have it as a subprocedure it's quite easy to put into a service program.
Once you have it into a service program it's quite easy to make a UDF, or User Defined Function, out of it so you can do stuff like select PrimaryKey, SomeDescriptiveColumn, EmailAddress from tableInQuestion where VerifyEmail(EmailAddress)='N'

Where VerifyEmail is the results of your evolution from subroutine to internal subprocedure to service program subprocedure to user defined function.

And none of this was just style for style's sake. I even left out the whole fixed format vs free format argument.

Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600 Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: Mike Cunningham <mike.cunningham-***@public.gmane.org>
To: Midrange Systems Technical Discussion <midrange-l-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org>
Date: 10/15/2014 09:17 AM
Subject: RE: Syntax check a string as a valid email address
Sent by: "MIDRANGE-L" <midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org>



This is RPG to try and catch the types of errors we have seen. It was
written about 5 years ago so could probably use a refresh to use some new
bifs, but it works for us. It is in a callable app that accepts the email
and sends back the vaild and error values

C Test BEGSR
C EVAL Valid = 'Y'
C EVAL Error = *BLANK

C* must not be all blanks
C IF Email = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'E-mail is blank'
C LEAVESR
C ENDIF
C* must contain at least one '@' sign
C EVAL sPos = %scan('@':Email)
C EVAL @Pos = sPos
C IF sPos = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required @ sign'
C LEAVESR
C ENDIF
C* error if contains more that one '@' sign
C IF %scan('@':Email:Spos+1) > 0
C EVAL Valid = 'N'
C EVAL Error = 'More than one @ sign'
C LEAVESR
C ENDIF
C* must contain at least one '.' sign after the first '@' sign
C IF %scan('.':Email:Spos+1) = 0
C EVAL Valid = 'N'
C EVAL Error = 'Missing required . (period)'
C LEAVESR
C ENDIF
C* error if contains a blank
C IF %scan(' ':%trim(Email)) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an embedded blank'
C LEAVESR
C ENDIF
C* split address into left and right sides
C EVAL LeftSide = %subst(Email:1:@pos-1)
C EVAL RightSide = %subst(Email:@pos+1)
C* left address may not be blank
C IF LeftSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Left side address missing'
C LEAVESR
C ENDIF
C* left address may not start with a '.'
C IF %scan('.':LeftSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not end with a '.'
C IF %subst(LeftSide:%len(%trim(LeftSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Left side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* left address may not have a double '.'
C IF %scan('..':LeftSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* check for left-side valid characters
C EVAL sPos = %check(CheckLeft:LeftSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' +
%trim(%editc(sPos:'4'))
C LEAVESR
C ENDIF
C* right address may not be blank
C IF RightSide = *BLANK
C EVAL Valid = 'N'
C EVAL Error = 'Right side address missing'
C LEAVESR
C ENDIF
C* right address may not start with a '.'
C IF %scan('.':RightSide) = 1
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not start +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not end with a '.'
C IF %subst(RightSide:%len(%trim(RightSide)):1) =
C '.'
C EVAL Valid = 'N'
C EVAL Error = 'Right side address may not end +
C with a . (period)'
C LEAVESR
C ENDIF
C* right address may not have a double '.'
C IF %scan('..':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a double +
C . (period)'
C LEAVESR
C ENDIF
C* right address may not have a '.-' string
C IF %scan('.-':RightSide) > 0
C EVAL Valid = 'N'
C EVAL Error = 'Address may not have a +
C . (period) - (dash) string'
C LEAVESR
C ENDIF
C* check for right-side valid characters
C EVAL sPos = %check(CheckRight:RightSide)
C IF sPos > 0
C EVAL Valid = 'N'
C EVAL Error = 'Has an invalid character at +
C position ' +
C %trim(%editc(sPos+@pos:'4'))
C LEAVESR
C ENDIF
C ENDSR

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org] On Behalf Of
John Yeung
Sent: Tuesday, October 14, 2014 7:46 PM
To: Midrange Systems Technical Discussion
Subject: Re: Syntax check a string as a valid email address
Post by Vinay Gavankar
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?
While regex is a very nice tool to have in the toolbox, if it's not
already in the toolbox, this is a task that, in my opinion, is not bad
just using RPG's BIFs. I guess it might depend on precisely what you want
to accept as "valid syntax" of an e-mail address, but for basic "eyeball"
tests, %SCAN goes a long way. Maybe throw in %CHECK if you're so
inclined.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Ken Sims
2014-10-15 14:59:21 UTC
Permalink
Raw Message
On Wed, 15 Oct 2014 13:17:28 +0000, Mike Cunningham
Post by Mike Cunningham
This is RPG to try and catch the types of errors we have seen. It was written about 5 years ago so could probably use a refresh to use some new bifs, but it works for us. It is in a callable app that accepts the email and sends back the vaild and error values
If I'm reading it correctly, it also needs some additional code to
make sure that it doesn't halt if the @ sign is in the first or last
positions of the email address field.

Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
r***@public.gmane.org
2014-10-15 15:22:22 UTC
Permalink
Raw Message
I was going to say no it doesn't because it checks left and right to see
if they are blank. However, I bet your observation would cause an
execution error.
EVAL LeftSide = %subst(Email:1:@pos-1)
If the whole email address was '@mydomain.com' then @pos would be 1. Thus
making the results of @pos-1 be equal to zero. Which may make the %subst
operation get violently ill.


Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: Ken Sims <mdrg8066-***@public.gmane.org>
To: midrange-l-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Date: 10/15/2014 10:59 AM
Subject: Re: Syntax check a string as a valid email address
Sent by: "MIDRANGE-L" <midrange-l-bounces-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org>



On Wed, 15 Oct 2014 13:17:28 +0000, Mike Cunningham
Post by Mike Cunningham
This is RPG to try and catch the types of errors we have seen. It was
written about 5 years ago so could probably use a refresh to use some new
bifs, but it works for us. It is in a callable app that accepts the email
and sends back the vaild and error values

If I'm reading it correctly, it also needs some additional code to
make sure that it doesn't halt if the @ sign is in the first or last
positions of the email address field.

Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
John Yeung
2014-10-15 17:18:00 UTC
Permalink
Raw Message
Post by r***@public.gmane.org
I was going to say no it doesn't because it checks left and right to see
if they are blank. However, I bet your observation would cause an
execution error.
operation get violently ill.
No, %SUBST is fine with zero length, and it says so right in the manual.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Ken Sims
2014-10-15 20:20:58 UTC
Permalink
Raw Message
On Wed, 15 Oct 2014 13:18:00 -0400, John Yeung
Post by John Yeung
No, %SUBST is fine with zero length, and it says so right in the manual.
Actually I had in mind the %SUBSTs where the starting position is
spos+1.

Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
John Yeung
2014-10-15 21:01:41 UTC
Permalink
Raw Message
Post by Ken Sims
On Wed, 15 Oct 2014 13:18:00 -0400, John Yeung
Post by John Yeung
No, %SUBST is fine with zero length, and it says so right in the manual.
Actually I had in mind the %SUBSTs where the starting position is
spos+1.
Well, I was responding to Rob, who said he thought %SUBST would fail
on zero length. There's no problem if '@' is the first character.

You're right that the code fails for '@' in the rightmost character,
though with certain additional conditions. It has to be the only '@'
in the whole field, and it has to be the very last possible character
in the field (so in a 50-char field, it would have to be in position
50, and all other 49 characters would have to be something else). In
this case, it would never make it to %SUBST because it would have
already failed on %SCAN (which is probably what you meant, because
that's what has the spos+1 starting position).

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Ken Sims
2014-10-16 02:59:38 UTC
Permalink
Raw Message
On Wed, 15 Oct 2014 17:01:41 -0400, John Yeung
Post by John Yeung
In
this case, it would never make it to %SUBST because it would have
already failed on %SCAN (which is probably what you meant, because
that's what has the spos+1 starting position).
Yes, %SCAN was actually what I meant.

Ken
Opinions expressed are my own and do not necessarily represent the views
of my employer or anyone in their right mind.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Buck Calabro
2014-10-15 15:52:39 UTC
Permalink
Raw Message
Post by John Yeung
Post by Vinay Gavankar
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?
While regex is a very nice tool to have in the toolbox, if it's not
already in the toolbox, this is a task that, in my opinion, is not bad
just using RPG's BIFs.
Usually, when I do this sort of thing, it's because I want to prevent
typos, not because I want to guarantee the address is deliverable. For
Post by John Yeung
I guess it might depend on precisely what you
want to accept as "valid syntax" of an e-mail address, but for basic
"eyeball" tests, %SCAN goes a long way. Maybe throw in %CHECK if
you're so inclined.
Valid is not in the eye of the beholder and not even in the eye of
RFC822. Valid is in the eye of the issuer. Well, one definition of
'valid' anyway. While le_maître_Hélène.Renée_O'***@gmail.com might
be a legal, RFC822 compliant address, Google won't issue that address to
her. Wanadoo.fr will, though. No one is going to issue the legal but
useless "@"@co The point is that a parser might accept it but the email
provider won't.

Anyway, an example of an RFC822 regex can be seen here:
http://ex-parrot.com/~pdw/Mail-RFC822-Address.html
--buck
--
'I had nothing to offer anybody except my own confusion' - Jack Kerouac
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-***@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-***@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/m
John Yeung
2014-10-15 18:19:08 UTC
Permalink
Raw Message
Post by Buck Calabro
Post by John Yeung
I guess it might depend on precisely what you
want to accept as "valid syntax" of an e-mail address, but for basic
"eyeball" tests, %SCAN goes a long way. Maybe throw in %CHECK if
you're so inclined.
Valid is not in the eye of the beholder and not even in the eye of
RFC822. Valid is in the eye of the issuer. Well, one definition of
'valid' anyway.
Right. The definition of "valid" you've just described isn't the
definition I meant.

The point of the language that I used was to capture *your* use case
of trying to catch typos, which I'm sure is the OP's use case as well.
Because that's what almost all of us (in the IT trenches) are doing
when we have these checks. And it's almost all we *can* do, since
there isn't any completely reliable programmatic way to tell whether a
given e-mail address actually exists and is deliverable.

So the kind of checking we want to do *is* up to us, the beholder.
For some of us, it will probably be a net win if we reject non-ASCII
characters (just to take one example). For others of us, that may be
a horrible piece of logic to use.

John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Scott Klement
2014-10-15 18:35:36 UTC
Permalink
Raw Message
Yeah, if you go by RFC 822, almost anything with an @ symbol in it is a
"valid" e-mail address. Though, RFC 822 is outdated, and RFC 2822 is
somewhat better in this respect.

The regular expressions that I've used do not allow all possibilities in
the RFCs, however... they're based more on what people commonly use
for e-mails. In other words, there may be a handful of e-mail addresses
that are technically "valid", but are rejected. This sort of thing is
very unusual, but possible. It's better to reject the handful of
addresses using a very strange syntax than it is to allow just about
anything, since the typo mistakes are far more common than the "weird"
addresses.

But, getting this exactly right can be tricky. The reason I recommend
using a regular expression is that there are expressions out there that
are widely used all over the internet that you can easily incorporate in
your RPG program. Since these have been well-tested, they are usually a
pretty good solution.

If you make up your own checking routine using things like %SCAN,
%SUBST, %CHECK, etc, you may be able to make something that works well,
but it's hard (when done that way) to get something as widely used and
tested as the ones you can get with a regular expression.

That's my 2 cents, anyway.
Post by John Yeung
Post by Buck Calabro
Post by John Yeung
I guess it might depend on precisely what you
want to accept as "valid syntax" of an e-mail address, but for basic
"eyeball" tests, %SCAN goes a long way. Maybe throw in %CHECK if
you're so inclined.
Valid is not in the eye of the beholder and not even in the eye of
RFC822. Valid is in the eye of the issuer. Well, one definition of
'valid' anyway.
Right. The definition of "valid" you've just described isn't the
definition I meant.
The point of the language that I used was to capture *your* use case
of trying to catch typos, which I'm sure is the OP's use case as well.
Because that's what almost all of us (in the IT trenches) are doing
when we have these checks. And it's almost all we *can* do, since
there isn't any completely reliable programmatic way to tell whether a
given e-mail address actually exists and is deliverable.
So the kind of checking we want to do *is* up to us, the beholder.
For some of us, it will probably be a net win if we reject non-ASCII
characters (just to take one example). For others of us, that may be
a horrible piece of logic to use.
John Y.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Barbara Morris
2014-10-15 18:39:12 UTC
Permalink
Raw Message
Post by Barbara Morris
...
You could explicitly set the length of the regex_t structure to 640.
...
Oops ... I misremembered the correct length of the regex_t struct. It is
656.

Sorry about that. Here's the program I just used to check it.

#include <stdio.h>
#include <regex.h>
main()
{
printf("sizeof(regex_t) is %d\n", sizeof(regex_t));
}

It prints: sizeof(regex_t) is 656
--
Barbara
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request-Zwy7GipZuJhWk0Htik3J/***@public.gmane.org
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
Loading...