Change code formatting
This commit is contained in:
@ -6,10 +6,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WGneu
|
||||
{
|
||||
static class Validator
|
||||
{
|
||||
namespace WGneu {
|
||||
static class Validator {
|
||||
|
||||
private static readonly Dictionary<string, string[][]> PHONE_NRS = new() {
|
||||
{ "43", new string[][] {
|
||||
@ -35,17 +33,14 @@ namespace WGneu
|
||||
};
|
||||
|
||||
|
||||
public static ValidationResult CheckNumericInput(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckNumericInput(TextBox input) {
|
||||
return CheckNumericInput(input, -1);
|
||||
}
|
||||
|
||||
private static ValidationResult CheckNumericInput(TextBox input, int maxLen)
|
||||
{
|
||||
private static ValidationResult CheckNumericInput(TextBox input, int maxLen) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (Char.IsDigit(ch))
|
||||
text += ch;
|
||||
@ -55,8 +50,7 @@ namespace WGneu
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (maxLen >= 0 && input.Text.Length > maxLen)
|
||||
{
|
||||
if (maxLen >= 0 && input.Text.Length > maxLen) {
|
||||
input.Text = input.Text.Substring(0, maxLen);
|
||||
input.CaretIndex = Math.Min(pos, maxLen);
|
||||
}
|
||||
@ -64,31 +58,23 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckPhoneNumber(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckPhoneNumber(TextBox input) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v == 0 && input.Text.Length - i >= 2 && ch == '0' && input.Text[i + 1] == '0') {
|
||||
v++; i++;
|
||||
text += "+";
|
||||
} else if (ch == '(' && input.Text.Length - i >= 3 && input.Text[i + 1] == '0' && input.Text[i + 2] == ')') {
|
||||
i += 2;
|
||||
}
|
||||
else if (v == 0 && ch == '0')
|
||||
{
|
||||
} else if (v == 0 && ch == '0') {
|
||||
v += 3;
|
||||
text += "+43";
|
||||
}
|
||||
else if (v == 0 && ch == '+')
|
||||
{
|
||||
} else if (v == 0 && ch == '+') {
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
else if (v > 0 && char.IsDigit(ch))
|
||||
{
|
||||
} else if (v > 0 && char.IsDigit(ch)) {
|
||||
if (PHONE_NRS.Any(kv => text == "+" + kv.Key))
|
||||
text += " ";
|
||||
if (text.StartsWith("+43 ")) {
|
||||
@ -118,24 +104,18 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckEmailAddress(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckEmailAddress(TextBox input) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
bool domain = false;
|
||||
for (int i = 0; i < input.Text.Length; i++)
|
||||
{
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (domain)
|
||||
{
|
||||
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch))
|
||||
{
|
||||
if (domain) {
|
||||
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch)) {
|
||||
if (!(text.Last() == '.' && ch == '.'))
|
||||
text += char.ToLower(ch);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (ch == '@') domain = true;
|
||||
if (!char.IsControl(ch) && !char.IsWhiteSpace(ch))
|
||||
text += ch;
|
||||
@ -158,8 +138,7 @@ namespace WGneu
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckLfbisNr(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckLfbisNr(TextBox input) {
|
||||
var res = CheckNumericInput(input, 7);
|
||||
if (!res.IsValid)
|
||||
return res;
|
||||
@ -173,18 +152,15 @@ namespace WGneu
|
||||
return new(true, "Not implemented yet");
|
||||
}
|
||||
|
||||
public static ValidationResult CheckUstIdInput(TextBox input)
|
||||
{
|
||||
public static ValidationResult CheckUstIdInput(TextBox input) {
|
||||
return new(false, "Not implemented yet");
|
||||
}
|
||||
|
||||
public static void SetInputInvalid(TextBox input)
|
||||
{
|
||||
public static void SetInputInvalid(TextBox input) {
|
||||
input.BorderBrush = System.Windows.Media.Brushes.Red;
|
||||
}
|
||||
|
||||
public static void SetInputValid(TextBox input)
|
||||
{
|
||||
public static void SetInputValid(TextBox input) {
|
||||
input.ClearValue(TextBox.BorderBrushProperty);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user