Results 1 to 8 of 8
  1. #1
    Helen269 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8

    Validation for British postcodes

    Just a quick question - how would I write a validation or input mask in a table for a British postcode? They vary and can be LN NLL or LLN NLL or LLNN NLL where N = number and L = letter.



    And is there a way of setting the case of an input field in a form to either uppercase or lowercase?

    Thank you. :-)

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Info about British Postal Code validation can be found here
    http://interim.cabinetoffice.gov.uk/.../postcode.aspx

    You can get info about the required regex expression at
    http://interim.cabinetoffice.gov.uk/...stCodeType.htm

  3. #3
    Helen269 is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    8
    Thanks, I think I'll go with

    >L?09\ 0LL"

    which, while it doesn't work with compass-point London postcodes (N1 1AB for example), is good enough for what I want to do.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For what its worth, here is a function to check the format.

    Code:
    Public Function ValidatePC(pPC As String) As String
    
    'validates format is correct.
    'still need to add checks for invalid lettters in certain positions
    
       Const Alpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
       Dim strPC As String
       Dim SearchChar As String
       Dim PCode As String
       Dim isValid As Boolean
       Dim TestPos As Integer
       Dim x As Integer
       Dim y As Integer
       'LN NLL or LLN NLL or LLNN NLL
    
       'set default return value
       ValidatePC = "Invalid PC"   ' PC = Postal Code
    
       strPC = UCase(pPC)
       Select Case Len(strPC)
          Case 6
             'LN NLL
             For x = 1 To 6
                TestPos = 0
                SearchChar = Mid(strPC, x, 1)
                Select Case x
                   Case 1, 5, 6
                      isValid = InStr(Alpha, SearchChar) > 0
                      If Not isValid Then
                         Exit For
                      End If
                   Case 2, 4
                      isValid = IsNumeric(SearchChar)
                      If Not isValid Then
                         Exit For
                      End If
                   Case 3
                End Select
             Next
          Case 7
             'LLN NLL
             For x = 1 To 7
                TestPos = 0
                SearchChar = Mid(strPC, x, 1)
                Select Case x
                   Case 1, 2, 6, 7
                      isValid = InStr(Alpha, SearchChar) > 0
                      If Not isValid Then
                         Exit For
                      End If
                   Case 3, 5
                      isValid = IsNumeric(SearchChar)
                      If Not isValid Then
                         Exit For
                      End If
                   Case 4
                End Select
             Next
          Case 8
             'LLNN NLL
             For x = 1 To 8
                TestPos = 0
                SearchChar = Mid(strPC, x, 1)
                Select Case x
                   Case 1, 2, 7, 8
                      isValid = InStr(Alpha, SearchChar) > 0
                      If Not isValid Then
                         Exit For
                      End If
                   Case 3, 4, 6
                      isValid = IsNumeric(SearchChar)
                      If Not isValid Then
                         Exit For
                      End If
                   Case 5
                End Select
             Next
          Case Else
    
       End Select
    
       If isValid Then
          ValidatePC = strPC
       End If
    
    End Function
    Last edited by ssanfu; 02-22-2012 at 07:09 PM. Reason: edit code

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Thanks Steve.

    I just copied this from the website I mentioned earlier.

    Please note the following:-


    • The letters Q, V and X are not used in the first position.
    • The letters I, J and Z are not used in the second position.
    • The only letters to appear in the third position are A, B, C, D, E, F, G, H, J, K, S, T, U and W.
    • The only letters to appear in the fourth position are A, B, E, H, M, N, P, R, V, W, X and Y.
    • The second half of the Postcode is always consistent numeric, alpha, alpha format and the letters C, I, K, M, O and V are never used.

    These conventions may change in the future if operationally required.
    *GIR 0AA is a Postcode that was issued historically and does not confirm to current rules on valid Postcode formats, It is however, still in use.
    Helen269 said she found a solution to solve her needs. But for others who may read this, I have added the material.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I saw the post from Helen, but I added the code anyway. I saw the positional restrictions (via your post) but didn't have time to add them to the function.

    Now it's time for and , then

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Steve,
    I didn't intend for you to update the function. I just wanted all the info in one spot in case someone else came looking for similar info.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    No problem... I just hate having/posting unfinished code. It works, but it is incomplete . My issue.... Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. validation
    By slimjen in forum Forms
    Replies: 6
    Last Post: 10-12-2011, 01:19 PM
  2. Validation Rule Help!
    By confidego in forum Access
    Replies: 8
    Last Post: 07-20-2011, 12:54 PM
  3. Replies: 1
    Last Post: 04-22-2011, 08:40 AM
  4. password validation
    By RycherX in forum Forms
    Replies: 1
    Last Post: 02-20-2010, 03:55 PM
  5. Calendar problem for British user
    By saylindara in forum Reports
    Replies: 15
    Last Post: 08-16-2009, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums