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

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 1
Title Test Details 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
   Displaying page 1 of 1 pages; Items 1 to 1

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