Skip to content

Instantly share code, notes, and snippets.

@vmandic
Created February 8, 2021 15:29
Show Gist options
  • Save vmandic/9f4fb6dfa9e57e4785a37cf112ec52a0 to your computer and use it in GitHub Desktop.
Save vmandic/9f4fb6dfa9e57e4785a37cf112ec52a0 to your computer and use it in GitHub Desktop.
Croatian post code number with HR prefix checker
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