Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Validate email and phone number

ronaldo_aparecido
Contributor
0 Kudos

Hi guys

There are a function to validate phone number types bt user ?

And i need a function to validate email too.

Thanks

I try search in sdn but i didnt find.

5 REPLIES 5

former_member196331
Active Contributor
0 Kudos

HI, Email u can check it by using.

PARAMETERS : P_MAIL   TYPE AS CHECKBOX

   IF P_MAIL IS  NOT INITIAL.

     IF P_MAILID EQ '<enter email address>' OR

        P_MAILID EQ ' '.

       MESSAGE 'Please Enter valid E-mailid' TYPE 'E'.

     ELSE.

       MATCHER = CL_ABAP_MATCHER=>CREATE(

                    PATTERN = `\w+(\.\w+)*@(\w+\.)+(\w{2,4})`

                    IGNORE_CASE = 'X'

                    TEXT = P_MAILID ).

       IF MATCHER->MATCH( ) IS INITIAL.

         MESSAGE 'Please Enter valid E-mailid'  TYPE 'E'.

*      ELSE.

*        MESSAGE 'Format OK' TYPE 'I'.

       ENDIF.

     ENDIF.

   ENDIF.

0 Kudos

In the same way number also.

PARAMETERS: TEL_NO TYPE CHAR8.

FIND REGX '([1-9)\1[0-9]{6}' IN TEL_NO.

IF SY-SUBCR EQ 0.

WRITE:/ 'NUMBER'.

ELSE.

WRITE:/ 'NUMBER IS INVLAID.

and also check function module

NUMERIC_CHECK

0 Kudos

NewB,

Thanks for CL_ABAP_MATCHER.So never heard/used this Class.

Seems quite an usefull one.

K.Kiran.

Former Member
0 Kudos

Hi Ronaldo Aparecido,

try this FM

SX_INTERNET_ADDRESS_TO_NORMAL

Thanks,

Vijay SR

Former Member
0 Kudos

Try this.

Email id validation.

data : lr_matcher type ref to CL_ABAP_MATCHER.

Data v_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 = v_pattern

Text = ’test@gmail.com’).

CALL METHOD lr_matcher->match

RECEIVING

success = v_sucess.

IF v_sucess = abap_false.

Message 'Invalid email id' TYPE 'I'.

ENDIF.