Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

regex validation: valid matches not found

j4johnOct 4 2006 — edited Oct 5 2006

Hi

I'm trying to use a regex to validate the format (not the content!) of email addresses. The best regex if found for this so far is

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

which I've tested using http://regexlib.com/RETester.aspx

Strings which produce matches using this tester fail validation when I use the same pattern as an item-level validation on an Apex page.

I know that there are some different regex dialects out there, so maybe that's the problem...

Can anybody help out with an explanation - or even a fix :) ?

Many thanks

john

Comments

Chet Justice
I am not familiar with regex but I did read this great post the other day on the SQL/PLSQL forum by cd.

429716

If that doesn't help you, you'd probably get better help over there (hopefully from cd himself).

chet
j4john
Thanks Chet,

Hadn't spotted cd's thread (on which I've now created a cross-ref to this one).

john
cd_2
The problem seems to be a missing "*" metacharacter. I've put a small test case together:
WITH t AS (SELECT 'Test@oracle.com' email
             FROM dual
            UNION 
           SELECT '1@oracle.com' 
             FROM dual
          )
SELECT t.email 
     , REGEXP_SUBSTR(t.email, '^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$') orig_check
     , REGEXP_SUBSTR(t.email, '^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z]*[-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$') new_check
  FROM t
  ;        
I'm going to deal with inet specific values (IP4 addresses, emails, URLs) in the second part of my regex introduction.

C.
j4john
Thankyou C,

Your fix does the trick.

I still don't understand why I got different results from http://regexlib.com/RETester.aspx (assuming it is POSIX compliant) and Apex.

I look forward to your next installment.

jd
cd_2
Maybe you should try another regex testing software? 2 out of 3 could give you a hint which implementation could have a bug.

C.
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 2 2006
Added on Oct 4 2006
5 comments
4,128 views