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: 

RegEx ?

former_member194669
Active Contributor
0 Kudos

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

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

former_member156446
Active Contributor
0 Kudos

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]

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

0 Kudos

Rich,

Thanks

Your reply solved my issue.

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

former_member194669
Active Contributor
0 Kudos

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