Two ways to Check if email is valid in ABAP : Function Vs Regex

Check if email is valid is a common business requirement for input email address field.

Email is structural list

Email Regular Expression (Regex)

General Email Regex

Up to RFC 5322 Official Standard, which defines the Standard of email address, the Regex must be


Regex in ABAP

The most used Regular Expression in ABAP for email address is:


Regex in Javascript

For Javascript, the regular expression is, hopefully, shorter 🙂


Email Regex for other languages

In this link, find the long list of Email Regular Expression for others common languages:
Python, Swift, PHP, Perl / Ruby, Ruby , .NET.

Check if email is Valid

Check if email is valid for input Field SAP

For the input field, make sure you define the email address field based on the data element AD_SMTPADR.
SAP will handle the validation of the email automatically.

The Domain of data element AD_SMTPADR is name also AD_SMTPADR.


The Domain AD_SMTPADR has 2 Conversion routines:

Check if email is valid in ABAP with Function

In ABAP, the validity of the email address can be check with the standard function
PS: This function is called in the conversion routine of AD_SMTPADR (CONVERSION_EXIT_SXIDN_INPUT).

The type of Address is ‘INT’ for Address email.

  TYPES: sx_addr_type  TYPE sx_addrtyp, "R/3 Addresstype
         sx_addr       TYPE so_rec_ext . "Address in plain string

  TYPES: BEGIN OF sx_address,           "SAPconnect general addr
         type        TYPE sx_addr_type,
         address     TYPE sx_addr,
       END OF sx_address.

  CONSTANTS: cx_t_int    TYPE sx_addr_type VALUE 'INT'.  "SMTP address

  DATA: ls_addr_unst      TYPE sx_address.
  DATA: ls_addr           TYPE sx_address.
  DATA: lv_address_normal TYPE sx_address.
  DATA: lv_local          TYPE sx_addr.
  DATA: lv_domain         TYPE sx_addr.
  DATA: lv_comment        TYPE sx_addr.

  ls_addr_unst-type    = cx_t_int.
  ls_addr_unst-address = p_email. " P_email : input

      address_unstruct     = ls_addr_unst
      address_normal       = lv_address_normal
      local                = lv_local
      domain               = lv_domain
      comment              = lv_comment
      addr_normal_no_upper = ls_addr
      error_address_type   = 1
      error_address        = 2
      error_group_address  = 3
      OTHERS               = 4.
  IF sy-subrc NE 0 .
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

Check if email is valid in ABAP with Regex

The Regular expression for email to be used in ABAP is

The Class CL_ABAP_MATCHER provides methods to create regular expression and do match check.

  DATA: lv_pattern TYPE string.
  DATA: lv_success TYPE char1. "abap_pool. " ABAP_FALSE/TRUE
  DATA: lr_matcher TYPE REF TO cl_abap_matcher.

  lv_pattern = '^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[azA-Z]{2,9})
  lr_matcher = cl_abap_matcher=>create(
                      pattern = lv_pattern
                      text = '[email protected]' ) .
      lr_matcher = cl_abap_matcher=>create(
            pattern       = lv_pattern
            text          = p_email " P_EMAIL: input
            ignore_case   = abap_false
            simple_regex  = abap_false
            no_submatches = abap_false ).

      CALL METHOD lr_matcher->match
          success = lv_success.

      IF lv_success = abap_true.
        MESSAGE 'Email is valid' TYPE 'I'.
        MESSAGE 'Email is not valid' TYPE 'W'.
    CATCH cx_sy_regex.
      MESSAGE 'Error occurs' TYPE 'E'.
    CATCH cx_sy_matcher .
      MESSAGE 'Error occurs' TYPE 'E'.