SAP ABAP- Validate email address using a regular expression, by using this we can not validate the existance of email address but we can validate uviversal email format.
Resourse used : SAP class CL_ABAP_REGEX and CL_ABAP_MATCHER .
Regular expression for email validation
'^[_a-zA-Z0-9-] (\.[_a-zA-Z0-9-] )*@[a-zA-Z0-9-] (\.[a-zA-Z0-9-] )*(\.[a-zA-Z]{2,4})$'
REPORT ZSAPN_VALIDATE_EMAIL.
PARAMETERS P_EMAIL TYPE STRING.
DATA:GO_REGEX TYPE REF TO CL_ABAP_REGEX,
GO_MATCHER TYPE REF TO CL_ABAP_MATCHER.
DATA: L_PAT(500) TYPE C.
L_PAT = '^[_a-zA-Z0-9-] (\.[_a-zA-Z0-9-] )*@[a-zA-Z0-9-] (\.[a-zA-Z0-9-] )*(\.[a-zA-Z]{2,4})$' .
CREATE OBJECT GO_REGEX
EXPORTING
PATTERN = L_PAT
IGNORE_CASE = ABAP_TRUE.
TRANSLATE P_EMAIL TO LOWER CASE.
GO_MATCHER = GO_REGEX->CREATE_MATCHER( TEXT = P_EMAIL )."lt_node_op4 ).
IF GO_MATCHER->MATCH( ) IS INITIAL.
WRITE:/ 'Email is not valid'.
ELSE.
WRITE :/ 'Email is valid'.
ENDIF.
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP MM SD Consultant
Contact : serkurumsal@yandex.com
Social Plugin