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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find UK Postcode (post code)
Expression
\A(([a-zA-Z]{1,2}\d{1,2})|([a-zA-Z]{2}\d[a-zA-Z]{1}))\x20{0,1}\d[a-zA-Z]{2}\Z
Description
I used this in C#.NET to check the validity of UK postcode entries. It successfully matches all acceptable formats (with or without a space) but does not check that the actual postcode is valid due to constant changes. Hope this helps - Jon NOTE: If you are not using in .NET yoy may need to replace \d with [0-9], \A with ^, and \Z with $.
Matches
S1 1AA, S11 1AA, SS1 1AA, SS11 1AA, SW1X 1AA
Non-Matches
S1X 1AA
Author Rating: Not yet rated. Jon Bellamy
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

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