Title |
Test
Find
US States
|
Expression |
^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$ |
Description |
Just a simple US State regex. Requires valid 2 letter abbreviations. |
Matches |
CO | GA | TX |
Non-Matches |
A | ZZ | Florida |
Author |
Rating:
Not yet rated.
Brandon Hunt
|
Source |
|
Your Rating |
|
Title: US all state codes with comma separated validation regex
Name: Sriram
Date: 5/5/2023 9:57:52 AM
Comment:
I need regex for Us state codes with comma separated
Title: Fixed now
Name: Brandon Hunt
Date: 12/20/2006 11:51:24 AM
Comment:
Thanks for the pointer, Dave. I fixed the ?: portion. It should now work as expected.
I think this was originally from a Miva regex page I found on the web when I needed a decent state regex.
Title: Incorrectly matches :AK | :AL | :AR | :AZ
Name: Dave Ryan
Date: 12/17/2006 7:55:31 PM
Comment:
The :? is backwards since this makes the : optional which allows :AK etc.. The original expression had this reversed so that you do not capture. (?: - a non-capturing block. It appears this expression was copied from one in RegExBuddy.