× 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.



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 ...

Follow-Ups:
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.