× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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@xxxxxxxxxxxx] On Behalf Of rob@xxxxxxxxx
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@xxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
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@xxxxxxxxxxxx>



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@xxxxxxxxxxxx] 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

On Tue, Oct 14, 2014 at 2:27 PM, Vinay Gavankar <vinaygav@xxxxxxxxx>
wrote:
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@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: 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-2024 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.