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
[mail]@[Domain].[Extension]

Email Regular Expression (Regex)

General Email Regex

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

(?:[a-z0-9!#$%&’*+/=?^_{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_{|}~-]+)*|”(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01-x09x0bx0cx0e-x7f])*”)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)])

Regex in ABAP

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

‘^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[azA-Z]{2,9})

Regex in Javascript

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

^[-a-z0-9~!$%^&*_=+}{‘?]+(.[-a-z0-9~!$%^&*_=+}{‘?]+)*@([a-z0-9_][-a-z0-9_]*(.[-a-z0-9_]+)*.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(:[0-9]{1,5})?$/i

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 input field, make sure you define the email address field based on the data element AD_SMTPADR.
SAP wil handle the validation of the email automatically.

The Domain of data element AD_SMTPADR is name also AD_SMTPADR.

AD_SMTPADR

The Domain AD_SMTPADR has 2 Conversion routines:
CONVERSION_EXIT_SXIDN_INPUT
CONVERSION_EXIT_SXIDN_OUTPUT

Check if email is valid in ABAP with Function

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

Check also   List of important SAP Good Movement BAPI (Create,Cancel & Getdetails)

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

Check if email is valid in ABAP with Regex

The Regular expression for email to be used in ABAP is
^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]*[0-9a-zA-Z].)+[azA-Z]{2,9})$

Check also   Display Popup Window in WebDynpro Abap

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