RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

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
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

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.


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials