Я не знаком с обозначениями «Мне нравится», # и * используется там, где они были, я хотел бы немного проверить здесь. Этот фрагмент кода в Интернете и хотел бы знать, делает ли он это как следует. Код, плюс некоторые некоторые комментарии я включил:Почтовый индекс Валидация и как обозначение
Function ValidPostCode(ByVal PostCode As String) As Boolean
'----------------------------------------------------------
' Deals with the postcodes of the form:
'AN NAA
'ANN NAA
'AAN NAA
'ANA NAA
'AANA NAA
'AANN NAA
'has issues with spaces and obscure entries like "England".
'Notes from Wiki::
'As all formats end with 9AA, the first part of a postcode can easily be extracted by ignoring the last three characters
'Areas with only single-digit districts: BR, FY, HA, HD, HG, HR, HS, HX, JE, LD, SM, SR, WC, WN, ZE (although WC is always subdivided by a further letter, e.g. WC1A).
'Areas with only double-digit districts: AB, LL, SO.
'Areas with a district '0' (zero): BL, BS, CM, CR, FY, HA, PR, SL, SS (BS is the only area to have both a district 0 and a district 10).
'The following central London single-digit districts have been further divided by inserting a letter after the digit and before the space: EC1–EC4 (but not EC50), SW1, W1, WC1, WC2, and part of E1 (E1W), N1 (N1C and N1P), NW1 (NW1W) and SE1 (SE1P).
'The letters QVX are not used in the first position.
'The letters IJZ are not used in the second position.
'The only letters to appear in the third position are ABCDEFGHJKPSTUW when the structure starts with A9A.
'The only letters to appear in the fourth position are ABEHMNPRVWXY when the structure starts with AA9A.
'The final two letters do not use the letters CIKMOV, so as not to resemble digits or each other when hand-written.
'Post code sectors are one of ten digits: 0 to 9 with 0 only used once 9 has been used in a post town, save for Croydon and Newport (see above).
'-----------------------------------------------------------
Dim Parts() As String
PostCode = UCase$(PostCode)
Parts = Split(PostCode)
If PostCode = "GIR 0AA" Or PostCode = "SAN TA1" Or _
(Parts(1) Like "#[A-Z][A-Z]" And _
(Parts(0) Like "[A-Z]#" Or Parts(0) Like "[A-Z]#[0-9ABCDEFGHJKSTUW]" Or _
Parts(0) Like "[A-Z][A-Z]#" Or Parts(0) Like "[A-Z][A-Z]#[0-9ABEHMNPRVWXY]")) Then
ValidPostCode = ((Parts(0) Like "[BEGLMSW]#*" Or _
Parts(0) Like "A[BL]#*" Or _
Parts(0) Like "B[ABDHLNRST]#*" Or _
Parts(0) Like "C[ABFHMORTVW]#*" Or _
Parts(0) Like "D[ADEGHLNTY]#*" Or _
Parts(0) Like "E[CHNX]#[AMNRVY]" Or _
Parts(0) Like "F[KY]#*" Or _
Parts(0) Like "G[LU]#*" Or _
Parts(0) Like "H[ADGPRSUX]#*" Or _
Parts(0) Like "I[GPV]#*" Or _
Parts(0) Like "K[ATWY]#*" Or _
Parts(0) Like "L[ADELNSU]#*" Or _
Parts(0) Like "M[EKL]#*" Or _
Parts(0) Like "N[EGNPRW]#*" Or _
Parts(0) Like "O[LX]#*" Or _
Parts(0) Like "P[AEHLOR]#*" Or _
Parts(0) Like "R[GHM]#*" Or _
Parts(0) Like "S[AEGKLMNOPRSTWY]#*" Or _
Parts(0) Like "T[ADFNQRSW]#*" Or _
Parts(0) Like "W[ACDFNRSV]#*" Or _
Parts(0) Like "UB#*" Or _
Parts(0) Like "YO#*" Or _
Parts(0) Like "ZE#*") And _
Parts(1) Like "*#[!CIKMOV][!CIKMOV]")
Else
ValidPostCode = False
End If
End Function
Пожалуйста, если кто-то может помочь и, возможно, объяснить код тщательно я был бы очень благодарен.
Спасибо
Использование регулярных выражений может быть проще. –
Вот ссылка документации Microsoft: [VBA Like Operator] (https://msdn.microsoft.com/en-us/library/office/gg251796.aspx). Документы VBA являются золотым рудником информации и стоят закладок. –