TFCJamieFay
Active Member
- Joined
- Oct 3, 2007
- Messages
- 480
Hi All,
I'm trying to create a filter that will stop any duff postcodes being entered by the end user. I have this piece of code that I found online, but it doesn't work for all postcodes.
The problem I have is that it doesn't work for postcodes in central London.
i.e. For the code EC1A 3RF, the "A" after the "1" can be any of the following"A,M,N,R,V or Y". I have changed the pattern to allow this but it doesn't work.
Can anyone see why as I'm tearing my hair out...?!
Many thanks,
Jay
Ps. There are also other postcodes such as EC2? as well but I've only started on this one for now.
I'm trying to create a filter that will stop any duff postcodes being entered by the end user. I have this piece of code that I found online, but it doesn't work for all postcodes.
The problem I have is that it doesn't work for postcodes in central London.
i.e. For the code EC1A 3RF, the "A" after the "1" can be any of the following"A,M,N,R,V or Y". I have changed the pattern to allow this but it doesn't work.
Can anyone see why as I'm tearing my hair out...?!
Code:
'This is the expression that validates the postcode
RgExp.Pattern = "(?:(?:AL|B[ABDHLNRS]?|" _
& "C[ABFHMORTVW]|D[AEHLNTY]||EC?[AMNRVY]|E[NX]?|FY|GL|GU|" _
& "H[ADGPRUX]|I[GP]|KT|L[ADELNSU]?|M[EK]?|" _
& "N[EGNPRW]?|O[LX]|P[ELOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|" _
& "T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO)" _
& "\d(?:\d|[A-Z])? \d[A-Z]{2})"
'Does the fed in string match the pattern?
If RgExp.Test(strInput) = True Then
IsUKPostcode = "Valid"
Else
Many thanks,
Jay
Ps. There are also other postcodes such as EC2? as well but I've only started on this one for now.