Helpers: Add Normalizer to normalize street names in addresses

This commit is contained in:
lorenz.stechauner committed 2026-09-28 16:59:39 +02:00
1 parent d2f1b4b94c
commit c7180426fe
9 files changed
+1502 -8

No files matched your search

+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);
}
}
}