Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Email Validation...Urgent Plzz

Former Member
0 Kudos

Hi All,

I have a parameter on the selection screen wherin multiple email addresses will be entered with the ' ; ' as the seperator.

I have written a code for single email validation , but it wont work for multiple.

Can u please help me in that n tell me about the changes that needed to be done.

CODE

&----


*& Form validate_p_mail

&----


FORM validate_p_mail USING p_mail.

DATA : l_var1(20) ,

l_var2(50) ,

l_var3(25) ,

l_var4(25) ,

l_var5(25) ,

l_var6(25) ,

l_mail TYPE string.

CONSTANTS: c_temp(50) TYPE c VALUE ' ~`!#$%^&*()+=|\}]{[":;<>?/'.

l_mail = p_mail .

IF NOT p_mail IS INITIAL .

IF l_mail CA c_temp .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

SPLIT l_mail AT '@' INTO l_var1 l_var2 .

IF l_var1 IS INITIAL.

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF.

IF l_var2 CA '@' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var2 CA '.' .

SPLIT l_var2 AT '.' INTO l_var3 l_var4 .

ENDIF .

IF l_var3 IS INITIAL .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var4 CA '.' .

SPLIT l_var4 AT '.' INTO l_var5 l_var6 .

IF l_var6 CA '.' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

ENDIF .

ENDIF.

ENDFORM. " validate_p_mail

Thank you...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hey Omkar check this code...

<b>&----


*& Report ZVALIDEMAIL

*&

&----


*&

*&

&----


REPORT zvalidemail MESSAGE-ID ztmp.

DATA : w_part1(200) ,

w_part2(200) ,

w_email TYPE string,

w_continue TYPE i VALUE 1,

BEGIN OF t_emails OCCURS 0,

email TYPE string,

END OF t_emails.

PARAMETERS: p_email TYPE string LOWER CASE.

CONSTANTS: c_temp(50) TYPE c VALUE ' ~`!#$%^&*()+=|\}]{[":;<>?/'.

AT SELECTION-SCREEN.

CLEAR: t_emails, t_emails[], w_email.

w_email = p_email.

IF NOT w_email IS INITIAL .

WHILE w_continue EQ 1.

SPLIT w_email AT ';' INTO w_part1 w_part2 .

IF w_part1 IS INITIAL AND w_part2 IS INITIAL.

MESSAGE e000 WITH 'Enter a Valid Email address' .

ENDIF.

IF sy-subrc EQ 0.

PERFORM validate_p_mail USING w_part1.

t_emails-email = w_part1.

APPEND t_emails.

CLEAR w_email.

IF w_part2 IS NOT INITIAL.

MOVE w_part2 TO w_email.

SHIFT w_email LEFT DELETING LEADING ' '.

w_continue = 1.

ELSE.

EXIT.

ENDIF.

ELSE.

w_continue = 0.

ENDIF.

ENDWHILE.

ENDIF.

START-OF-SELECTION.

WRITE:/ 'EMAIL IDs are: '.

SKIP.

LOOP AT t_emails.

WRITE:/ t_emails-email.

SKIP.

ENDLOOP.

&----


*& Form validate_p_mail

&----


FORM validate_p_mail USING p_mail.

DATA : l_var1(20) ,

l_var2(50) ,

l_var3(25) ,

l_var4(25) ,

l_var5(25) ,

l_var6(25) ,

l_mail TYPE string.

CONSTANTS: c_temp(50) TYPE c VALUE ' ~`!#$%^&*()+=|\}]{[":;<>?/'.

l_mail = p_mail .

IF NOT p_mail IS INITIAL .

IF l_mail CA c_temp .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

SPLIT l_mail AT '@' INTO l_var1 l_var2 .

IF l_var1 IS INITIAL.

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF.

IF l_var2 CA '@' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var2 CA '.' .

SPLIT l_var2 AT '.' INTO l_var3 l_var4 .

ENDIF .

IF l_var3 IS INITIAL .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var4 CA '.' .

SPLIT l_var4 AT '.' INTO l_var5 l_var6 .

IF l_var6 CA '.' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

ENDIF .

ENDIF.

ENDFORM. " validate_p_mail</b>

Reward me points if ur problem has been solved..

Message was edited by:

Pradeep Kharore

6 REPLIES 6

Former Member
0 Kudos

Hey Omkar check this code...

<b>&----


*& Report ZVALIDEMAIL

*&

&----


*&

*&

&----


REPORT zvalidemail MESSAGE-ID ztmp.

DATA : w_part1(200) ,

w_part2(200) ,

w_email TYPE string,

w_continue TYPE i VALUE 1,

BEGIN OF t_emails OCCURS 0,

email TYPE string,

END OF t_emails.

PARAMETERS: p_email TYPE string LOWER CASE.

CONSTANTS: c_temp(50) TYPE c VALUE ' ~`!#$%^&*()+=|\}]{[":;<>?/'.

AT SELECTION-SCREEN.

CLEAR: t_emails, t_emails[], w_email.

w_email = p_email.

IF NOT w_email IS INITIAL .

WHILE w_continue EQ 1.

SPLIT w_email AT ';' INTO w_part1 w_part2 .

IF w_part1 IS INITIAL AND w_part2 IS INITIAL.

MESSAGE e000 WITH 'Enter a Valid Email address' .

ENDIF.

IF sy-subrc EQ 0.

PERFORM validate_p_mail USING w_part1.

t_emails-email = w_part1.

APPEND t_emails.

CLEAR w_email.

IF w_part2 IS NOT INITIAL.

MOVE w_part2 TO w_email.

SHIFT w_email LEFT DELETING LEADING ' '.

w_continue = 1.

ELSE.

EXIT.

ENDIF.

ELSE.

w_continue = 0.

ENDIF.

ENDWHILE.

ENDIF.

START-OF-SELECTION.

WRITE:/ 'EMAIL IDs are: '.

SKIP.

LOOP AT t_emails.

WRITE:/ t_emails-email.

SKIP.

ENDLOOP.

&----


*& Form validate_p_mail

&----


FORM validate_p_mail USING p_mail.

DATA : l_var1(20) ,

l_var2(50) ,

l_var3(25) ,

l_var4(25) ,

l_var5(25) ,

l_var6(25) ,

l_mail TYPE string.

CONSTANTS: c_temp(50) TYPE c VALUE ' ~`!#$%^&*()+=|\}]{[":;<>?/'.

l_mail = p_mail .

IF NOT p_mail IS INITIAL .

IF l_mail CA c_temp .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

SPLIT l_mail AT '@' INTO l_var1 l_var2 .

IF l_var1 IS INITIAL.

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF.

IF l_var2 CA '@' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var2 CA '.' .

SPLIT l_var2 AT '.' INTO l_var3 l_var4 .

ENDIF .

IF l_var3 IS INITIAL .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ELSEIF l_var4 CA '.' .

SPLIT l_var4 AT '.' INTO l_var5 l_var6 .

IF l_var6 CA '.' .

MESSAGE e000 WITH

'Enter a Valid Email address' .

ENDIF .

ENDIF .

ENDIF.

ENDFORM. " validate_p_mail</b>

Reward me points if ur problem has been solved..

Message was edited by:

Pradeep Kharore

0 Kudos

to add to Pradeep's code.

for the splitting of emails at ';' you can do this

SPLIT w_email AT ';' INTO table t_emails .

if t_emails[] is initial .

**error message as no email is entered

else.

loop at t_emails....

do the validation

endloop .

endif .

Clemenss
Active Contributor
0 Kudos

Hi Omkar Mirvankar,

congratulations re-inventing just another wheel

You may use SAP standard function module

SX_INTERNET_ADDRESS_TO_NORMAL

which will give you a SY-SUBRC <> 0 for invalid mail addresses.

As it checks one address only, you may define


data:
  lt_mails type string,
  lv_mail type string.
split p_mail at ';' into lt_mails.
loop at lt_mails into lv_mail.
  CALL FUNCTION 'SX_INTERNET_ADDRESS_TO_NORMAL'
* check the parameters - I'm not logged on
  if sy-subrc <> 0.
** error 'invalid mail address' lv_mail in p_mail
  endif.
endloop.

Regards,

Clemens

Former Member
0 Kudos

Hi Clemens,

I am looking for same kinkd of FM and felt happy by looking at this FM, but unfortunately this is not working for example if you enter email as xyz@abccom. DOT after '@' is missing here. In this case also sy-subrc is zero. :-<

Regards,

Surya.

Clemenss
Active Contributor
0 Kudos

Hi Surya,

what can I say?

I thought to have seen a remark in the FM that it is RFC822 compliant. For CRM they created a class, maybe somewhat better.

This seems to be really difficult for that company...

Regards,

Clemens

Former Member
0 Kudos

hmm.. good FM.

You can use this FM inside while loop in place of subroutine...