Documents: Add Bio-KSt. to footer
All checks were successful
Test / Run tests (push) Successful in 2m24s

This commit is contained in:
2025-07-23 17:07:10 +02:00
parent c61c2e3fcd
commit fad1e28c06
6 changed files with 83 additions and 14 deletions

View File

@@ -628,5 +628,55 @@ namespace Elwig.Helpers {
return new(true, null);
}
public static ValidationResult CheckOrganicAuthorityCode(TextBox input, bool required) {
string text = "";
int pos = input.CaretIndex;
for (int i = 0, v = 0; i < input.Text.Length; i++) {
char ch = char.ToUpper(input.Text[i]);
if (v < 2 && char.IsAsciiLetter(ch)) {
v++;
text += ch;
} else if ((v == 2 || v == 6) && ch == '-') {
v++;
text += ch;
} else if (v >= 2 && char.IsLetterOrDigit(ch)) {
if (text.StartsWith("AT")) {
if (v == 3 && ch == 'B' || v == 4 && ch == 'I' || v == 5 && ch == 'O') {
v++;
text += ch;
} else if (v > 6 && char.IsAsciiDigit(ch)) {
v++;
text += ch;
}
} else {
v++;
text += ch;
}
}
if (i == input.CaretIndex - 1) {
pos = text.Length;
} else if (text.StartsWith("AT") && v >= 10) {
break;
}
}
input.Text = text;
input.CaretIndex = pos;
if (text.Length == 0)
return required ? new(false, "Bio-Kontrollstellen-Code ist nicht optional") : new(true, null);
if (text.StartsWith("AT")) {
if (text.Length != 10) {
return new(false, "Bio-Kontrollstellen-Code ist ungültig");
}
} else {
return new(false, "Not implemented yet");
}
return new(true, null);
}
}
}