Skip to main content
Participating Frequently
May 11, 2007
Question

Regular expression form validation

  • May 11, 2007
  • 2 replies
  • 442 views
I have a form field that I currently validate using <cfinput pattern="^([a-zA-Z]{2}$" validate="regular_expression" Type="text" required="yes"> (other attributes also including name, etc). Anyway, this validates that the input must be 2 letters, but know I need to validate the field so that "NA" is allowed. Is there a way to do that?
    This topic has been closed for replies.

    2 replies

    Inspiring
    May 21, 2007
    The regular expression
    [^NA]
    causes NA to be escaped.

    The expression
    [NA]
    causes NA to NOT be escaped.

    So if I read your code right, you should insert a [^NA] but if this fails, do the other = [NA]
    I always need to test these things :-)

    Hope this helps,

    Hans
    RTH_RTHAuthor
    Participating Frequently
    May 21, 2007
    Thanks for the help!

    I did some research and did this ^(?!NA)([a-zA-Z]{2}$ and I think it worked.....
    Inspiring
    May 12, 2007
    i may be going blind, but i see "NA" as being 2 letters, which will pass
    your validation...
    --

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com
    RTH_RTHAuthor
    Participating Frequently
    May 21, 2007
    No, I'm the one who is blind!

    I meant to say that "NA" is NOT allowed....sorry

    So, how would I go about using the regular expression validation I currently have but validate that the "NA" pair isn't used.