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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top