Application Development and Automation 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: 
Read only

RegEx ?

former_member194669
Active Contributor
0 Likes
937

Hi,

I am using following RegEx to validate email id entered, But somehow it is not working correctly, ie after giving correct email also it not working


data : email type c 30.
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
  pattern = `w+(.w+)*@(W+.)+(w{2,4})`
  ignore_case = 'X'
  text = email ).
if matcher->match( ) is initial.
  message 'Wrong Format' type 'I'.
else.
  message 'Format OK' type 'I'.
endif

Note : SCN site restrictions i could not paste the email id here , but i am giving email value as 'ars.ars @ abc.com'. without any spaces

Any Info ?

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
880

You might want to try this one, it works ok for me, Found it on the internet.

data : email(30) type c .  "<- set value of mail address
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
  pattern = `^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$`
  ignore_case = 'X'
  text = email ).
if matcher->match( ) is initial.
  message 'Wrong Format' type 'I'.
else.
  message 'Format OK' type 'I'.
endif.

Regards,

Rich Heilman

You might want to try this one, it works ok for me, Found it on the internet.

data : email(30) type c .  "<- set value of mail address
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
  pattern = `^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$`
  ignore_case = 'X'
  text = email ).
if matcher->match( ) is initial.
  message 'Wrong Format' type 'I'.
else.
  message 'Format OK' type 'I'.
endif.

Regards,

Rich Heilman

4 REPLIES 4
Read only

former_member156446
Active Contributor
0 Likes
880

isnt reg ex:?

(".+@.+\\.[a-z]+")


[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}

[More info|http://www.regular-expressions.info/email.html] and [1 more|http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=47]

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
881

You might want to try this one, it works ok for me, Found it on the internet.

data : email(30) type c .  "<- set value of mail address
data matcher type ref to cl_abap_matcher.
matcher = cl_abap_matcher=>create(
  pattern = `^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$`
  ignore_case = 'X'
  text = email ).
if matcher->match( ) is initial.
  message 'Wrong Format' type 'I'.
else.
  message 'Format OK' type 'I'.
endif.

Regards,

Rich Heilman

Read only

0 Likes
880

Rich,

Thanks

Your reply solved my issue.

But still i don't understand why mine was failed.

Read only

former_member194669
Active Contributor
0 Likes
880

I found the problem.

The correct regex will be


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

instead of


pattern = `w+(.w+)*@(W+.)+(w{2,4})`

because of capital W in the regex