AS400-Array

105 pts.
Tags:
RPG
RPGLE
i am doing the coding to check the email adress,eg:try@yahoo.com.after the character @,means(@yahoo.com),the rest of the characters called email domain.How to extract the email domain from the email address input by the user by using array and to check whether the user key in the email domain?

Answer Wiki

Thanks. We'll let you know when a new response is added.

here is a procedure I have used to <i>validate </i>an email address

<pre>
**********************************************************************
* VALIDEMAILADDR – VALIDATES NAME FOR VALIDITY AS EMAIL ADDRESS *
**********************************************************************

P VALIDEMAILADDR B EXPORT

D VALIDEMAILADDR PI N
D NAME 255 CONST

D DOTLOC S 3 0
D ATLOC S 3 0

D VALID C CONST(*ON)
D NOTVALID C CONST(*OFF)

C EVAL ATLOC = %SCAN(‘@’:%TRIM(NAME))
C EVAL DOTLOC = %SCAN(‘.’:%TRIM(NAME):ATLOC + 1)

* NO ‘@’ RETURN NOT VALID
* NOT AT LEAST ONE ‘.’ AFTER THE ‘@’ RETURN NOT VALID
* NOT AT LEAST ONE CHARACTER BEFORE THE ‘@’ RETURN NOT VALID
* STARTS WITH ‘.’ RETURN NOT VALID
* MORE THAN ONE ‘@’ RETURN NOT VALID
* NOT AT LEAST ONE CHARACTER AFTER THE ‘@’ RETURN NOT VALID
* ENDS WITH ‘.’ RETURN NOT VALID
* TWO OR MORE CONSEQUTIVE ‘.’ RETURN NOT VALID
* ANY INVALID CHARACTERS RETURN NOT VALID \/:?’, *BLANK
C IF ATLOC = 0
C OR DOTLOC = 0
C OR ATLOC = 1
C OR %SUBST(%TRIM(NAME):1:1) = ‘.’
C OR %SCAN(‘@’:NAME:ATLOC + 1) <> 0
C OR ATLOC + 1 = DOTLOC
C OR %SUBST(%TRIM(NAME):%LEN(%TRIM(NAME)):1)
C = ‘.’
C OR %SCAN(‘..’:NAME) <> 0
C OR %SCAN(”:NAME) <> 0
C OR %SCAN(‘/’:NAME) <> 0
C OR %SCAN(‘:’:NAME) <> 0
C OR %SCAN(‘?’:NAME) <> 0
C OR %SCAN(””:NAME) <> 0
C OR %SCAN(‘,’:NAME) <> 0
C OR %SCAN(‘ ‘:%TRIM(NAME)) <> 0
C RETURN NOTVALID
C ENDIF

* NO ERRORS RETURN VALID
C RETURN VALID

P VALIDEMAILADDR E

</pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • astradyne
    Here's a routine I found a while ago which validates email addresses really well. I came across this technique in one of the online newsletters and I think it was Ted Holt who published it. If I'm mistaken my apologies to the author:
         p ValidEmail      b                   Export                
                                                                     
         D* Procedure interface                                      
         D ValidEmail      pi             1n                         
         D  iEmail                       80a   Const                 
                                                                     
         D wReturn         s              1n                         
                                                                     
         D Column          s             10u 0                       
         D CurrAction      s              5a                         
         D CurrentChar     s              1a                         
         D CurrState       s             10u 0                       
         D EOL             s              1a   inz(*loval)           
         D Ndx             s             10u 0                       
         D StringLength    s             10u 0                       
         D pos             s             10u 0                       
         D OuStatus        s             10u 0                       
    
         D AtSign          c                   const('@')                 
         D Period          c                   const('.')                 
         D Slash           c                   const('/')                 
         D QuestionMark    c                   const('?')                 
         D Exclamation     c                   const('!')                 
                                                                          
         C                   Eval      ouStatus = *Zero                   
         C                   Eval      Ndx = *Zero                        
         C                   Eval      StringLength = %len(%trimr(iEmail))
         C                   Eval      CurrState = 1                        
         C                   dou       (CurrState = *zero)                  
                                                                            
         C* Get the next character of the email address...                  
         C                   ExSr      GetCurrChar                          
                                                                            
         C* Retrieve the action from the state table...                     
         C                   Eval      pos = ((CurrState - 1) * 5) + Column 
         C                   Eval      CurrAction = %subst(Action(pos):1:5) 
         C                                                                  
                                                                            
         C* Carry out the action...                                         
         C                   Exsr      DoAction                             
                                                                            
         C* Set new state...                                                
         C                   Eval      pos = ((CurrState - 1) * 5) + Column 
         C                   Eval      Currstate =                          
         C                               CvtCharNum(%subst(Action(pos):7:1))
         C                   EndDo                                          
    
         C* Return the valid flag to the calling routine...
         C                   Eval      wReturn = Yes       
         C                   If        ouStatus > *Zeros   
         C                   Eval      wReturn = No        
         C                   EndIf                         
                                                           
         C                   Return    wReturn             
                                                           
                                                                                    
         C     GetCurrChar   BegSr                                                  
         C*    ===================                                                  
                                                                                    
         C* Access the next character of the string                                 
         C                   Eval      Ndx = Ndx + 1                                
         C                   If        (Ndx <= StringLength)                        
         C                   Eval      CurrentChar = %subst(iEmail:Ndx)             
         C                   Else                                                   
         C                   Eval      CurrentChar = EOL                            
         C                   EndIf                                                  
                                                                                    
         C* Determine which column of the state table to use                        
         C                   Select                                                 
         C                   When      (CurrentChar = *blank or                     
         C                             CurrentChar = Slash or       
         C                             CurrentChar = QuestionMark or
         C                             CurrentChar = Exclamation)   
         C                   Eval      Column = 1                   
         C                   When        (CurrentChar = EOL)        
         C                   Eval      Column = 2                   
         C                   When        (CurrentChar = AtSign)     
         C                   Eval      Column = 3                   
         C                   When        (CurrentChar = Period)     
         C                   Eval      Column = 4                   
         C                   Other                                  
         C                   Eval      Column = 5                   
         C                   Endsl                                  
         C                                                          
         C                   EndSr                                  
    
         C     DoAction      BegSr                         
         C*    ===================                         
         C                   If        CurrAction = 'error'
         C                   Eval      ouStatus = Ndx      
         C                   EndIf                         
         C                                                 
         C                   EndSr                         
                                                           
         P                 e                               
                                                           
    **                                                     
    error/0 error/0 error/0 error/0      /2                
    error/0 error/0      /3      /1      /2                
    error/0 error/0 error/0 error/0      /4                
    error/0 error/0 error/0      /5      /4                
    error/0 error/0 error/0 error/0      /6 
    error/0      /0 error/0      /5      /6 
    
    370 pointsBadges:
    report
  • astradyne
    Why don't the "code" tags work when posting in the discussions?
    370 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following