regular expression for case insensitive USA state codes

S

Stan

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
 
K

Kevin Spencer

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.
 
Top