Created
February 8, 2021 15:29
-
-
Save vmandic/9f4fb6dfa9e57e4785a37cf112ec52a0 to your computer and use it in GitHub Desktop.
Croatian post code number with HR prefix checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool IsCroatianPostOfficeNumberWithHRPrefix(string postCode) | |
{ | |
// ref: https://hr.wikipedia.org/wiki/Po%C5%A1tanski_broj | |
if (postCode.StartsWith("HR")) | |
{ | |
var postCodeWithoutHR = postCode.Substring(2); | |
if ( postCodeWithoutHR.StartsWith("10") | |
|| postCodeWithoutHR.StartsWith("20") | |
|| postCodeWithoutHR.StartsWith("21") | |
|| postCodeWithoutHR.StartsWith("22") | |
|| postCodeWithoutHR.StartsWith("23") | |
|| postCodeWithoutHR.StartsWith("31") | |
|| postCodeWithoutHR.StartsWith("32") | |
|| postCodeWithoutHR.StartsWith("33") | |
|| postCodeWithoutHR.StartsWith("34") | |
|| postCodeWithoutHR.StartsWith("35") | |
|| postCodeWithoutHR.StartsWith("40") | |
|| postCodeWithoutHR.StartsWith("42") | |
|| postCodeWithoutHR.StartsWith("43") | |
|| postCodeWithoutHR.StartsWith("44") | |
|| postCodeWithoutHR.StartsWith("47") | |
|| postCodeWithoutHR.StartsWith("48") | |
|| postCodeWithoutHR.StartsWith("49") | |
|| postCodeWithoutHR.StartsWith("51") | |
|| postCodeWithoutHR.StartsWith("52") | |
|| postCodeWithoutHR.StartsWith("53")) | |
{ | |
// NOTE: rest of the characters must be digits resulting in 5 digit number if it is a valid post code number in Croatia | |
return int.TryParse(postCodeWithoutHR, out var _); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment