Validate PLZ
This commit is contained in:
@ -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) {
|
||||||
|
Reference in New Issue
Block a user