regular expression for case insensitive USA state codes

Discussion in 'ASP .Net' started by Stan, May 16, 2006.

  1. Stan

    Stan Guest

    I have a very simple web form with a textbox and a regular expression
    validator. The regular expression I'm attempting to use doesn't work on the
    client side (Javascript) tho it works on the server side.

    Anyone have an idea of how to make this following regex work on the client
    side and case insensitive?

    The following works for CAPITALIZED letters (but I don't want the user to
    be forced into entering caps or do any Javascript tricks to capitalize when
    the user types.)

    MyRegex.ValidationExpression = "^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[ANU]
    |HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]
    |UT|V[AIT]|W[AIVY])$"

    A user in another Forum gave me this regular expression below, but it
    doesn't seem to work irregardless of the case.

    MyRegex.ValidationExpression = "/^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[ANU]
    |HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]
    |UT|V[AIT]|W[AIVY])$/i"


    Thanks in advance,
    Stan
    Stan, May 16, 2006
    #1
    1. Advertising

  2. Add this to the beginning: (?i)

    This is an instruction to the regular expression to ignore case.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Numbskull

    Hard work is a medication for which
    there is no placebo.

    "Stan" <> wrote in message
    news:Xns97C5A28524586aw3er4fresagss@69.28.186.121...
    >
    > I have a very simple web form with a textbox and a regular expression
    > validator. The regular expression I'm attempting to use doesn't work on
    > the
    > client side (Javascript) tho it works on the server side.
    >
    > Anyone have an idea of how to make this following regex work on the client
    > side and case insensitive?
    >
    > The following works for CAPITALIZED letters (but I don't want the user to
    > be forced into entering caps or do any Javascript tricks to capitalize
    > when
    > the user types.)
    >
    > MyRegex.ValidationExpression = "^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[ANU]
    > |HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]
    > |UT|V[AIT]|W[AIVY])$"
    >
    > A user in another Forum gave me this regular expression below, but it
    > doesn't seem to work irregardless of the case.
    >
    > MyRegex.ValidationExpression = "/^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[ANU]
    > |HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]
    > |UT|V[AIT]|W[AIVY])$/i"
    >
    >
    > Thanks in advance,
    > Stan
    Kevin Spencer, May 16, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,766
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Replies:
    2
    Views:
    2,793
    Malcolm
    Aug 20, 2005
  3. Replies:
    1
    Views:
    2,457
    Mark P
    Apr 6, 2007
  4. sabinosa

    case INsensitive regular expressions

    sabinosa, Oct 21, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    352
    Vijai Kalyan
    Oct 22, 2004
  5. Xah Lee
    Replies:
    4
    Views:
    931
Loading...

Share This Page