Add Bic and Plz validation

This commit is contained in:
2023-02-27 18:35:27 +01:00
parent f291504bd0
commit f965af5861
3 changed files with 98 additions and 16 deletions

View File

@ -49,7 +49,7 @@ namespace WGneu {
int pos = input.CaretIndex;
for (int i = 0; i < input.Text.Length; i++) {
char ch = input.Text[i];
if (Char.IsDigit(ch))
if (char.IsDigit(ch))
text += ch;
if (i == input.CaretIndex - 1)
pos = text.Length;
@ -63,13 +63,24 @@ namespace WGneu {
}
if (maxLen >= 0 && input.Text.Length > maxLen) {
input.Text = input.Text.Substring(0, maxLen);
input.Text = input.Text[..maxLen];
input.CaretIndex = Math.Min(pos, maxLen);
}
return new(true, null);
}
public static ValidationResult CheckPlz(TextBox input, bool optional) {
CheckNumericInput(input, true, 4);
if (optional && input.Text.Length == 0) {
return new(true, null);
} else if (input.Text.Length != 4) {
return new(false, "PLZ zu kurz");
} else {
return new(true, null);
}
}
public static ValidationResult CheckPhoneNumber(TextBox input, bool optional) {
string text = "";
int pos = input.CaretIndex;
@ -195,11 +206,50 @@ namespace WGneu {
return new(true, null);
}
public static ValidationResult CheckBic(TextBox input, bool optional) {
string text = "";
int pos = input.CaretIndex;
for (int i = 0, v = 0; i < input.Text.Length; i++) {
char ch = input.Text[i];
if ((v < 4 || v >= 6) && char.IsAscii(ch) && char.IsLetterOrDigit(ch)) {
v++;
text += char.ToUpper(ch);
} else if (v >= 4 && v < 6 && char.IsAscii(ch) && char.IsLetter(ch)) {
v++;
text += char.ToUpper(ch);
}
if (i == input.CaretIndex - 1)
pos = text.Length;
}
if (text.Length == 0) {
if (optional) return new(true, null);
return new(false, "BIC ist nicht optional");
}
if (text.Length > 11) {
text = text[..11];
pos = Math.Min(pos, 11);
}
if (text.Length == 11 && text.EndsWith("XXX"))
text = text[..8];
input.Text = text;
input.CaretIndex = pos;
if (text.Length != 11 && text.Length != 8)
return new(false, "BIC ist ungültig");
return new(true, null);
}
public static ValidationResult CheckLfbisNr(TextBox input, bool optional) {
var res = CheckNumericInput(input, optional, 7);
var res = CheckNumericInput(input, true, 7);
if (!res.IsValid)
return res;
if (input.Text.Length == 0)
if (optional && input.Text.Length == 0)
return new(true, null);
if (input.Text.Length != 7)
return new(false, "Betriebsnummer zu kurz");