Forum Stats

  • 3,876,217 Users
  • 2,267,082 Discussions


regex validation: valid matches not found

j4john Member Posts: 196 Blue Ribbon
edited Oct 5, 2006 5:09AM in APEX Discussions

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
which I've tested using

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



  • Chet Justice
    Chet Justice Member Posts: 574 Bronze Badge
    I am not familiar with regex but I did read this great post the other day on the SQL/PLSQL forum by cd.


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

  • j4john
    j4john Member Posts: 196 Blue Ribbon
    Thanks Chet,

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

  • cd_2
    cd_2 Member Posts: 5,021
    edited Oct 5, 2006 3:31AM
    The problem seems to be a missing "*" metacharacter. I've put a small test case together:
    WITH t AS (SELECT '[email protected]' email
                 FROM dual
               SELECT '[email protected]' 
                 FROM dual
         , REGEXP_SUBSTR(, '^([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(, '^([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.

  • j4john
    j4john Member Posts: 196 Blue Ribbon
    Thankyou C,

    Your fix does the trick.

    I still don't understand why I got different results from (assuming it is POSIX compliant) and Apex.

    I look forward to your next installment.

  • cd_2
    cd_2 Member Posts: 5,021
    edited Oct 5, 2006 5:09AM
    Maybe you should try another regex testing software? 2 out of 3 could give you a hint which implementation could have a bug.

This discussion has been closed.