Add telephone numbers
This commit is contained in:
@ -141,7 +141,7 @@ namespace Elwig.Helpers {
|
||||
public static ValidationResult CheckPhoneNumber(TextBox input, bool required) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0, v = 0; i < input.Text.Length && v < 15; i++) {
|
||||
for (int i = 0, v = 0; i < input.Text.Length && v <= 15; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v == 0 && input.Text.Length - i >= 2 && ch == '0' && input.Text[i + 1] == '0') {
|
||||
v++; i++;
|
||||
@ -154,21 +154,30 @@ namespace Elwig.Helpers {
|
||||
} else if (v == 0 && ch == '+') {
|
||||
v++;
|
||||
text += ch;
|
||||
} else if (v > 0 && char.IsAsciiDigit(ch)) {
|
||||
} else if (v > 0 && (char.IsAsciiDigit(ch) || ch == ' ' || ch == '-')) {
|
||||
if (PHONE_NRS.Any(kv => text == "+" + kv.Key))
|
||||
text += ' ';
|
||||
if (text.StartsWith("+43 ")) {
|
||||
var nr = text[4..];
|
||||
var vws = PHONE_NRS["43"];
|
||||
if (v >= 4 && v - 4 < vws.Length && vws[v - 4].Any(vw => nr.StartsWith(vw)))
|
||||
if (!text.EndsWith(" ") && v >= 4 && v - 4 < vws.Length && vws[v - 4].Any(vw => nr.StartsWith(vw))) {
|
||||
text += ' ';
|
||||
else if (nr == "1")
|
||||
} else if (nr == "1") {
|
||||
text += ' ';
|
||||
else if (v == 7 && nr.Length == 4)
|
||||
} else if (v == 7 && nr.Length == 4) {
|
||||
text += ' ';
|
||||
}
|
||||
var vw = text.Split(" ");
|
||||
if (char.IsAsciiDigit(ch)) {
|
||||
v++;
|
||||
text += ch;
|
||||
} else if (char.IsAsciiDigit(text[^1]) && vw.Length > 2 && v >= 10 && (vw[1].Length - 1 >= vws.Length || !vws[vw[1].Length - 1].Any(v => vw[1].StartsWith(v)))) {
|
||||
text += ch;
|
||||
}
|
||||
} else {
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
if (i == input.CaretIndex - 1)
|
||||
pos = text.Length;
|
||||
@ -182,7 +191,7 @@ namespace Elwig.Helpers {
|
||||
return new(false, "Telefonnummer zu kurz");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
return new(char.IsAsciiDigit(text[^1]), null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckEmailAddress(TextBox input, bool required) {
|
||||
|
Reference in New Issue
Block a user