[fix:] plz check was bad
This commit is contained in:
@@ -240,19 +240,27 @@ public static class AddressCreator
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(plz)) return false;
|
if (string.IsNullOrWhiteSpace(plz)) return false;
|
||||||
|
|
||||||
// For non-german countries, accept any non-empty postal code
|
var trimmedPlz = plz.Trim();
|
||||||
if (land.ToLower().Trim() != "germany" && land.ToLower().Trim() != "ger" && land.ToLower().Trim() != "" &&
|
var trimmedLand = 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)
|
// Check if it's a German country code
|
||||||
if (int.TryParse(plz, out var iplz))
|
var isGermany = trimmedLand == "germany" || trimmedLand == "ger" || trimmedLand == "de" ||
|
||||||
|
trimmedLand == "deutschland" || trimmedLand == "";
|
||||||
|
|
||||||
|
if (isGermany)
|
||||||
|
// For Germany (including empty land), accept numeric postal codes with 5 digits
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (iplz > 99999 || iplz < 10000) return false;
|
var iplz = Convert.ToInt32(trimmedPlz);
|
||||||
return true;
|
if (trimmedPlz.Length == 5) return true;
|
||||||
}
|
|
||||||
|
|
||||||
// If it can't be parsed as int, it's not a valid German postal code
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For non-German countries, accept any non-empty postal code
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user