cancel
Showing results for 
Search instead for 
Did you mean: 

Check if the e-mail addess is valid or not.

Former Member
0 Kudos

Hi,

How can I check if the email addres entered by the user is a valid email address or not ? I need a basic validation no need to check the validity of the domain.

Thanks & Regards

Gaurav Jain

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Gaurav,

check this code

data lv_email_addr type sx_address.

lv_email contains the email address

if lv_email is not initial.

move 'INT' to lv_email_addr-type.

move lv_email to lv_email_addr-address.

call function 'SX_INTERNET_ADDRESS_TO_NORMAL'

exporting

address_unstruct = lv_email_addr

exceptions

error_address_type = 1

error_address = 2

error_group_address = 3

others = 4.

if sy-subrc<>0

  • error

Thanks

Bala Duvvuri

Former Member
0 Kudos

check this code

janoliver_feist
Explorer
0 Kudos

Hi Gaurav!

One way to validate an email address is a regular expression.


data:
  lr_regex type ref to cl_abap_regex,
  lr_matcher type ref to cl_abap_matcher,
  lv_email_to_check type string.

create object lr_regex
  exporting
    pattern     = '[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'
    ignore_case = abap_true.

lr_matcher = lr_regex->create_matcher( text = lv_email_to_check ).

if lr_matcher->match( ) is initial.
* address invalid
else.
* address valid.
endif.

The used regular expression should cover all valid email addresses with a domain. For email addresses of the form <Account>@<IP-Address>, the regular expression needs some enhancement.

For a closer look at regular expressions for email addresses refer to

[http://www.regular-expressions.info/email.html]

Hope that helps,

regards,

Jan

Edited by: Jan Oliver Feist on Sep 26, 2008 12:28 PM

Former Member
0 Kudos

Hi Gaurav,

Read the context attribute which is attached to the Email field in the view then move the value to the one string.

data: email type string,

count type i,

email = <read from context>.

count = email.strlen.

do count times.

here write the logic to check for email like @ ....

enddo.

if you want to check the validation against check table then use ADR6 table to get check the validation for email address.