on 09-26-2008 10:57 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check this code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.