2009 Jan 20 7:41 PM
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 ?
a®
2009 Jan 20 7:49 PM
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
2009 Jan 20 7:49 PM
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]
2009 Jan 20 7:49 PM
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
2009 Jan 20 8:07 PM
Rich,
Thanks
Your reply solved my issue.
But still i don't understand why mine was failed.
a®
2009 Jan 20 8:40 PM
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
a®
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |