Helpers: Add Normalizer to normalize street names in addresses

This commit is contained in:
2026-09-29 19:04:12 +02:00
parent d8126e254d
commit fda337c3cb
9 changed files with 3193 additions and 8 deletions
+20
View File
@@ -711,5 +711,25 @@ namespace Elwig.Helpers {
return new(true, null);
}
public static ValidationResult CheckAddress(TextBox input, bool required, string? locality = null) {
var text = input.Text;
var (name, nr) = Utils.SplitAddress(text);
if (!string.IsNullOrWhiteSpace(nr)) {
var street = Normalizer.NormalizeStreetName(name.Replace(",", ""), locality);
var idx = input.CaretIndex;
input.Text = $"{street} {nr}".Trim();
if (idx >= (text.Length - nr.Length)) {
input.CaretIndex = street.Length + (idx - (text.Length - nr.Length)) + 1;
} else if (idx > 0) {
input.CaretIndex = idx;
}
}
if (text.Length == 0)
return required ? new(false, "Adresse ist nicht optional") : new(true, null);
return new(true, null);
}
}
}