Validate PLZ

This commit is contained in:
2023-03-13 19:15:43 +01:00
parent 568eedcdf3
commit ccaeedb4b1

View File

@ -60,15 +60,18 @@ namespace WGneu.Helpers {
return new(true, null); 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); CheckNumeric(input, true, 4);
if (optional && input.Text.Length == 0) { if (optional && input.Text.Length == 0) {
return new(true, null); return new(true, null);
} else if (input.Text.Length != 4) { } else if (input.Text.Length != 4) {
return new(false, "PLZ zu kurz"); 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) { public static ValidationResult CheckPhoneNumber(TextBox input, bool optional) {