MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Email ID validation in COBOL

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Mon May 08, 2006 12:37 pm    Post subject: Email ID validation in COBOL Reply with quote

I am looking for COBOL code to validate a well-formed email address. I saw a previous posting with Java Script code (http://www.mvsforums.com/helpboards/viewtopic.php?t=4796), but I could save some time if have anyone had already coded it in COBOL.

Thanks!
Back to top
View user's profile Send private message
vivek1983
Intermediate


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Thu May 11, 2006 9:16 am    Post subject: Reply with quote

Drammo,

Please find the code below:

Code:

 
  ************************************************************* 
 WORKING-STORAGE SECTION.                                     
************************************************************* 
 01 WS-LEN       PIC 9(09) VALUE ZERO.                         
 01 WS-MAIL-ID   PIC X(50) VALUE = 'GAN@INAUTIX.COM'.         
 01 WS-MAIL-CHAR REDEFINES WS-MAIL-ID                         
                 PIC X OCCURS 50 TIMES.                       
 01 WS-USER-NAME PIC X(25) VALUE SPACES.                       
 01 WS-DOM-NAME  PIC X(25) VALUE SPACES.                       
 01 WS-VAL-DOM PIC X(06) VALUE SPACES.                         
    88 VALID-DOM   VALUES ARE                                 
       'COM', 'NET', 'ORG', 'EDU'.                             
 01 WS-DOM-1     PIC X(19) VALUE SPACES.                       
 01 WS-SPL-CHARS PIC X(01) VALUE SPACES.                       
    88 SPL-CHARS   VALUES ARE                                 
       ',', ' ', '!', '#', '%', '$', '^', '&', '*',           
       '(', ')', '+', '{', '}', '[', ']', '/', '\'.           


*************************************************************
 PROCEDURE DIVISION.                                         
*************************************************************
 0000-BEGIN.                                                 

*// Split mail ids into 2 parts - user name and domain name //*                                                             

      UNSTRING WS-MAIL-ID DELIMITED BY '@' INTO               
         WS-USER-NAME                                         
         WS-DOM-NAME                                         
      COMPUTE WS-LEN = LENGTH(WS-USER-NAME)         
         
*// Domain name and username should not be spaces //*
      IF WS-DOM-NAME = SPACES                                 
        SET WS-INV-MAILID   TO TRUE                           
      END-IF                                                 

*// Check for special characters //*
      MOVE 1 TO WS-SUB                                       
      PERFORM VARYING WS-SUB UNTIL WS-SUB > 50               
       MOVE WS-MAIL-CHAR TO WS-SPL-CHARS                     
* // "jerry"@visual.com is a valid id. Checking is done here //*
       IF NOT (WS-SUB = 1 AND WS-MAIL-ID(1:1) = '"' AND       
          WS-MAIL-ID(WS-LEN , 1) = '"' )                     
        IF SPL-CHARS                                         
         SET WS-INV-MAILID   TO TRUE                         
        END-IF                                       
       END-IF                                         
      END-PERFORM                                     


      IF WS-USER-NAME > SPACES OR                     
         WS-DOM-NAME > SPACES                         
        SET WS-INV-MAILID   TO TRUE                   
      END-IF                                         

* // domain name should contain atlease one dot // *
      INSPECT WS-DOM-NAME TALLYING WS-COUNT FOR '.'   
      IF WS-COUNT = 0                                 
        SET WS-INV-MAILID   TO TRUE                   
      END-IF                                         

* // Check for valid domain entries (Com, org.. )  // *
      UNSTRING WS-DOM-NAME DELIMITED BY '.'           
               WS-DOM-1, WS-VAL-DOM                   
      IF NOT VALID-DOM                               
        SET WS-INV-MAILID   TO TRUE                   
      END-IF                                         
                                                     
      STOP RUN.                                       

     
                                     



Hope this helps..

Regards,
Vivek.G
Back to top
View user's profile Send private message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Fri May 12, 2006 7:22 am    Post subject: Reply with quote

Thanks Vivek!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group