[fix:] plz check was bad

This commit is contained in:
Elias Fierke
2025-12-14 14:30:33 +01:00
parent 174223ba9e
commit 2c22306fef

View File

@@ -239,20 +239,28 @@ public static class AddressCreator
public static bool CheckPLZ(string plz, string land) public static bool CheckPLZ(string plz, string land)
{ {
if (string.IsNullOrWhiteSpace(plz)) return false; if (string.IsNullOrWhiteSpace(plz)) return false;
// For non-german countries, accept any non-empty postal code
if (land.ToLower().Trim() != "germany" && land.ToLower().Trim() != "ger" && land.ToLower().Trim() != "" &&
land.ToLower().Trim() != "de" && land.ToLower().Trim() != "deutschland")
return true;
// For Germany, check if it's a valid numeric postal code (5 digits) var trimmedPlz = plz.Trim();
if (int.TryParse(plz, out var iplz)) var trimmedLand = land.ToLower().Trim();
{
if (iplz > 99999 || iplz < 10000) return false; // Check if it's a German country code
return true; var isGermany = trimmedLand == "germany" || trimmedLand == "ger" || trimmedLand == "de" ||
} trimmedLand == "deutschland" || trimmedLand == "";
// If it can't be parsed as int, it's not a valid German postal code if (isGermany)
return false; // For Germany (including empty land), accept numeric postal codes with 5 digits
try
{
var iplz = Convert.ToInt32(trimmedPlz);
if (trimmedPlz.Length == 5) return true;
return false;
}
catch
{
return false;
}
// For non-German countries, accept any non-empty postal code
return true;
} }
} }