Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Validaton COBOL/400 2

Status
Not open for further replies.

JSutor

MIS
Aug 11, 2004
30
US
Here is the code that I am using and the issure that is left behind. Any suggestion on another way or how to do it the way I am currently I would be greatful.

START-CHECK-EMAIL-ADDRESS.
*Reset counters.
MOVE ZEROS TO WS-AT-SYMBOL.
MOVE ZEROS TO WS-PERIODS.
MOVE ZEROS TO WS-EMAIL-SPACES.

*Check the address to make sure that it have at least one @ however no more than one.
INSPECT DEI-OUTBOUND-EMAIL-ADDRESS
TALLYING WS-AT-SYMBOL
FOR ALL "@".
IF WS-AT-SYMBOL < 1 OR WS-AT-SYMBOL > 1
MOVE WS-SETON TO DEO-INVALID-EMAIL-ADDRESS
MOVE WS-MESSAGE-06 TO DEO-MESSAGE-TEXT
GO TO END-CHECK-EMAIL-ADDRESS
END-IF.
Example of test passed:
aaaaaa@aaaaaaaa.com
aaaaaa@
aaaaaa@aaa aaaaa.c om
Example of failed:
aaaaaaaaaaaaaa.com
aaaa.aaaaaaaaaaaaa.com
aaaaaaaaa aaaaa.a aa

*Check to make sure that the address contains atleast one period, there can be multiple periods in an email address.
INSPECT DEI-OUTBOUND-EMAIL-ADDRESS
TALLYING WS-PERIODS
FOR ALL ".".
IF WS-PERIODS < 1
MOVE WS-SETON TO DEO-INVALID-EMAIL-ADDRESS
MOVE WS-MESSAGE-06 TO DEO-MESSAGE-TEXT
GO TO END-CHECK-EMAIL-ADDRESS
END-IF.
Example of test passed:
a aaaaa@aaaaaaaa.com
aaaaaa@aaa aaaaa.a aa
aaaa.aa aaa@aaa.aaaaa.com
Example of failed:
aaaaaa@aaaaaaaacom
aaaaaa@aaa aaaaa com
aaaa aaaaa@aaa aaaaa com

*Check to make sure that the address does not contains any spaces prior to the @.
INSPECT DEI-OUTBOUND-EMAIL-ADDRESS
TALLYING WS-EMAIL-SPACES
FOR ALL SPACES
BEFORE "@".
IF WS-EMAIL-SPACES > 0
MOVE WS-SETON TO DEO-INVALID-EMAIL-ADDRESS
MOVE WS-MESSAGE-06 TO DEO-MESSAGE-TEXT
GO TO END-CHECK-EMAIL-ADDRESS
END-IF.
Example of test passed:
aaaaaa@aaa aaaaa.com
aaaaaa@aaa aaaaa.c om
aaaa.aaaaa@aaa.aaaaa.com
Example of failed:
a aaaaa@aaaaaaaa.com
aaa aaa@aaa aaaaa. com
aaaa aaaaa@aaa aaaaa. com

*Check to make sure that the address does not contains any spaces after the @ but before the ".".
INSPECT DEI-OUTBOUND-EMAIL-ADDRESS
TALLYING WS-EMAIL-SPACES
FOR ALL SPACES
AFTER "@"
BEFORE ".".
IF WS-EMAIL-SPACES > 0
MOVE WS-SETON TO DEO-INVALID-EMAIL-ADDRESS
MOVE WS-MESSAGE-06 TO DEO-MESSAGE-TEXT
GO TO END-CHECK-EMAIL-ADDRESS
END-IF.
END-CHECK-EMAIL-ADDRESS.
EXIT.
Example of test passed:
aaaaaa@aaaaaaaa.c o m
aaaaaa@aaaaaaaa.c om
aaaa.aaaaa@aaa.aaaaa. com
Example of failed:
aaaaaa@a aaaaaaa.com
aaaaaa@aaa aaaaa. com
aaaa.aaaaa@a aaaaaaa. com

The only condition that I can figure how to test is after the final period to end of the email address.

Example of emails that slip through
aaaaaa@aaaaaaaa. com
aaaa.aaaaa@aaaaaaaa.c o m
aaaa@aaaaaaaa.
aaaa@aaaaaaaa.co m
 
Rather than checking for spaces in so many different ways, why not just check to see if there are any imbedded spaces anywhere?

Use the intrinsic function REVERSE to reverse your email address into a working field. Then use INSPECT to count the leading spaces.

Now use INSPECT to count the total number of spaces in the email address.

If there are more total number of spaces than leading spaces, then you have an extra imbedded space somewhere in the address.
 
Can you show me an example of the code I have never used the REVERSE statement

Thanks,
John
 
This is the simplest code I could come up with that would cover all the bases.
Code:
PERFORM VARYING TEXT-LENGTH FROM LENGTH OF EMAIL-ADDRESS BY -1 UNTIL TEXT-LENGTH < 5 
                 OR EMAIL-ADDRESS(TEXT-LENGTH:1) NOT = SPACE
    CONTINUE
END-PERFORM
IF TEXT-LENGTH < 5
    MOVE 'Y'                         TO ERROR-FLAG
ELSE
    MOVE 'N'                         TO ERROR-FLAG
    MOVE 'N'                         TO AT-FLAG
    MOVE 'N'                         TO DOT-FLAG
    MOVE 'N'                         TO THIS-CHAR
    PERFORM VARYING PTR-1 FROM 1 BY 1 UNTIL PTR-1 > TEXT-LENGTH OR ERROR-FLAG = 'Y'
         MOVE THIS-CHAR              TO PREV-CHAR
         MOVE EMAIL-ADDRESS(PTR-1:1) TO THIS-CHAR
         EVALUATE THIS-CHAR
             WHEN SPACE
                 MOVE 'Y'            TO ERROR-RLAG
             WHEN '.'
                 IF PTR-1 = 1 OR TEXT-LENGTH OR PREV-CHAR = '.' OR '@'
                     MOVE 'Y'        TO ERROR-FLAG
                 ELSE
                     IF AT-FLAG = 'Y'
                         MOVE 'Y'    TO DOT-FLAG
                     END-IF
                 END-IF
             WHEN '@'
                 IF PTR-1 = 1 OR TEXT-LENGTH OR PREV-CHAR = '.' OR '@' OR AT-FLAG = 'Y'
                     MOVE 'Y'        TO ERROR-FLAG
                 ELSE
                     MOVE 'Y'        TO AT-FLAG
                 END-IF
             WHEN OTHER
                 IF THIS-CHAR < SPACE OR > '~' OR = any illegal character
                     MOVE 'Y'        TO ERROR-FLAG
                 END-IF
         END-EVALUATE
    END-PERFORM
    IF AT-FLAG = 'N' OR DOT-FLAG = 'N'
        MOVE 'Y'                     TO ERROR-FLAG
    END-IF
END-IF
 
MOVE FUNCTION REVERSE(FIELD-1) TO FIELD-2.

If FIELD-1 contains 'ABCDEFbbb' (b=space)
then after the MOVE FIELD-2 = 'bbbFEDCBA'
 
Thanks to you both for the ideas I'll try them both out and let you know. I have a couple other ideas to. But thanks for the help.
 
This is an interesting problem. I thought that simple syntax checking of an e-mail address should be fairly straight forward. NOT! Turns out that even basic syntax checking is very difficult (see: There is a regular expression that is purported to validate an e-mail address syntactically following the RFC, but it's almost a page long (just the regular expression)! Were you running on the PC platform, you could use the Microsoft ActiveX regular expression parser and this regular expression to validate the e-mail address in your COBOL program. Don't suppose an equivalent exists for the iSeries.

Regards,

Glenn
 
Yeah there is just not simple way in COBOL to do this I have combine everyone suggestions including co-workers and have come up with a solution that appears work pretty good. Thanks again to everyone for the help and suggestion.

John
 
and have come up with a solution that appears work pretty good
Can you please post your solution for the benefit of members ?
 
Just an aside as another example of a command line type solution (provided the user was online to the internet)

1. Check for the presence of an @
2. Check for no blanks prior to the @
3. Make a command-line:
PING WHATEVER-IS-AFTER-THE-AT > PING.DAT
4. Have the user hit enter to acknowledge that the id will be validated. (this gives time for ping.dat to be written)
5. Read PING.DAT
6. If record one contains an IP address the id is valid.

Clive
 
Haha, I tried pinging nosuchsite.com and it exists:
Code:
Pinging nosuchsite.com [216.52.184.240] with 32 bytes of data:

Reply from 216.52.184.240: bytes=32 time=60ms TTL=237
Reply from 216.52.184.240: bytes=32 time=59ms TTL=237
Reply from 216.52.184.240: bytes=32 time=60ms TTL=237
Reply from 216.52.184.240: bytes=32 time=59ms TTL=237
Ping statistics for 216.52.184.240:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 59ms, Maximum = 60ms, Average = 59ms

Clive
 
Clive -

[nitpick]
The steps you outline do help validate the address, but passing the steps is NOT confirmation that the address is truly valid. In fact, an address that fails the validation steps can still be valid (e.g. the server you ping could be down temporarily; blanks are allowed before the @).

The following is a valid e-mail address sample containing a space before the '@':

joe doe<joe@abc.com>

All the ping does is indicate the server with the given name is up and responding to pings (and by inference, the domain is a valid one). The server may not, in fact, be the destination mail server. I believe the mail server is defined by an MX record in the DNS entry and may not even be in the same domain.
[\nitpick]

Regards.

Glenn
 
I think it is not practical basically because your server could be slow, or down.

However,
[nitpick]
I do not think it matters if the other server is down. In fact when I tested it, my own server was down. The ping failed but the returning of the first record with an IP did not.

I do not agree that you can have a blank in an email address "joe doe" is not a valid part of an email address.

I think the mail server address is not the same as the email address.
[/nitpick]

Having said that I think that trying to validate an email address is pointless. The most likely source of error is a typo which no validation routine could pick up.


Clive
 
I am on the road a lot lately and have time on my hands... so see if you like this one Glenn:

Code:
  ******************************************************************

       IDENTIFICATION DIVISION.

      ******************************************************************

       PROGRAM-ID.    EMAILVAL.
       AUTHOR.        Clive Cummins.
       INSTALLATION.  [URL unfurl="true"]www.tubularity.com[/URL]
       DATE-WRITTEN.  May  5,2005.

      *-****************************************************************
      *-                          EMAILVAL
      *-
      *-       VALIDATE AN EMAIL PASSED VIA THE COMMAND LINE.
      *-****************************************************************

      ******************************************************************

       ENVIRONMENT DIVISION.

      ******************************************************************

      ******************************************************************

       DATA DIVISION.

      ******************************************************************

      ******************************************************************
       WORKING-STORAGE SECTION.
      ******************************************************************

       01  PROGRAM-DETAILS.
           05  PROGRAM-RELEASE.
               10  PROGRAM-NAME PIC X(08) VALUE 'EMAILVAL'.
               10  PROGRAM-REL  PIC X(08) VALUE '  1.0.00'.

      ******************************************************************
       01  SYSTEM-COMMAND-LINE.
      ******************************************************************

           05  MY-BROWSER              PIC X(49)  VALUE
           '"C:\Program Files\Internet Explorer\iexplore.exe"'.
           05  FILLER                  PIC X(01)  VALUE SPACE.
           05  FILLER                  PIC X(49)  VALUE
           '[URL unfurl="true"]http://tubularity.com/tools/emailval/index.php?e='.[/URL]
           05  TEST-EMAIL              PIC X(80).

      ******************************************************************
       01  CALL9135-PARAMETERS.
      ******************************************************************

           05  CALL9135-CALL-FUNCTION  PIC X(01) VALUE 35 COMP-X.
           05  CALL9135-RETURN-CODE    PIC X(01) VALUE  0 COMP-X.
           05  CALL9135-COMMAND-LENGTH PIC X(01) VALUE  0 COMP-X.

      ******************************************************************

       PROCEDURE DIVISION.

      ******************************************************************

           ACCEPT TEST-EMAIL FROM COMMAND-LINE.

           DISPLAY SYSTEM-COMMAND-LINE UPON COMMAND-LINE.
           CALL x'91' USING CALL9135-RETURN-CODE
                            CALL9135-CALL-FUNCTION
                            CALL9135-COMMAND-LENGTH.

           GOBACK.


Kind regards,

Clive
 
Clive -

Hard to tell w/o the PHP code, but it seems to work OK on simple addresses. However, you need to look at RFC2822 to see the wide variety of valid e-mail addresses.

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top