From ccaeedb4b107bd08cb97a83990fd63402713c2ed Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 13 Mar 2023 19:15:43 +0100 Subject: [PATCH] Validate PLZ --- WGneu/Helpers/Validator.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WGneu/Helpers/Validator.cs b/WGneu/Helpers/Validator.cs index 8953f4c..0df4256 100644 --- a/WGneu/Helpers/Validator.cs +++ b/WGneu/Helpers/Validator.cs @@ -60,15 +60,18 @@ namespace WGneu.Helpers { return new(true, null); } - public static ValidationResult CheckPlz(TextBox input, bool optional) { + public static ValidationResult CheckPlz(TextBox input, bool optional, AppDbContext ctx) { CheckNumeric(input, true, 4); if (optional && input.Text.Length == 0) { return new(true, null); } else if (input.Text.Length != 4) { return new(false, "PLZ zu kurz"); - } else { - return new(true, null); } + int plz = int.Parse(input.Text); + if (!ctx.Postleitzahlen.Any(p => p.Plz == plz)) { + return new(false, "Ungültige PLZ"); + } + return new(true, null); } public static ValidationResult CheckPhoneNumber(TextBox input, bool optional) {