Use isAscii...()
This commit is contained in:
@ -131,7 +131,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static int Modulo(string a, int b) {
|
||||
if (a.Length == 0 || !a.All(char.IsDigit)) {
|
||||
if (a.Length == 0 || !a.All(char.IsAsciiDigit)) {
|
||||
throw new ArgumentException("First argument has to be a decimal string");
|
||||
} else if (b < 2) {
|
||||
throw new ArgumentException("Second argument has to be greater than 1");
|
||||
|
@ -34,12 +34,12 @@ namespace Elwig.Helpers {
|
||||
return CheckInteger(input, required, -1);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckInteger(TextBox input, bool required, int maxLen) {
|
||||
private static ValidationResult CheckInteger(TextBox input, bool required, int maxLen) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (char.IsDigit(ch))
|
||||
if (char.IsAsciiDigit(ch))
|
||||
text += ch;
|
||||
if (i == input.CaretIndex - 1)
|
||||
pos = text.Length;
|
||||
@ -89,7 +89,7 @@ namespace Elwig.Helpers {
|
||||
} else if (v == 0 && ch == '+') {
|
||||
v++;
|
||||
text += ch;
|
||||
} else if (v > 0 && char.IsDigit(ch)) {
|
||||
} else if (v > 0 && char.IsAsciiDigit(ch)) {
|
||||
if (PHONE_NRS.Any(kv => text == "+" + kv.Key))
|
||||
text += ' ';
|
||||
if (text.StartsWith("+43 ")) {
|
||||
@ -127,7 +127,7 @@ namespace Elwig.Helpers {
|
||||
for (int i = 0; i < input.Text.Length && text.Length < 256; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (domain) {
|
||||
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch)) {
|
||||
if ((char.IsAsciiLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch)) {
|
||||
if (!(text.Last() == '.' && ch == '.'))
|
||||
text += char.ToLower(ch);
|
||||
}
|
||||
@ -151,7 +151,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
var last = text.Split(".").Last();
|
||||
if (last.Length < 2 || !last.All(ch => char.IsAscii(ch) && char.IsLower(ch)))
|
||||
if (last.Length < 2 || !last.All(ch => char.IsAsciiLetterLower(ch)))
|
||||
return new(false, "E-Mail-Adresse ungültig");
|
||||
|
||||
return new(true, null);
|
||||
@ -163,9 +163,9 @@ namespace Elwig.Helpers {
|
||||
int v = 0;
|
||||
for (int i = 0; i < input.Text.Length && v < 34; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (char.IsLetterOrDigit(ch) && char.IsAscii(ch)) {
|
||||
if (((v < 2 && char.IsLetter(ch)) || (v >= 2 && v < 4 && char.IsDigit(ch)) || v >= 4) &&
|
||||
((!text.StartsWith("AT") && !text.StartsWith("DE")) || char.IsDigit(ch)))
|
||||
if (char.IsAsciiLetterOrDigit(ch)) {
|
||||
if (((v < 2 && char.IsAsciiLetter(ch)) || (v >= 2 && v < 4 && char.IsAsciiDigit(ch)) || v >= 4) &&
|
||||
((!text.StartsWith("AT") && !text.StartsWith("DE")) || char.IsAsciiDigit(ch)))
|
||||
{
|
||||
if (v != 0 && v % 4 == 0)
|
||||
text += ' ';
|
||||
@ -190,7 +190,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
var validation = (text[4..] + text[..4]).Replace(" ", "")
|
||||
.Select(ch => char.IsDigit(ch) ? ch.ToString() : (ch - 'A' + 10).ToString())
|
||||
.Select(ch => char.IsAsciiDigit(ch) ? ch.ToString() : (ch - 'A' + 10).ToString())
|
||||
.Aggregate((a, b) => a + b);
|
||||
if (Utils.Modulo(validation, 97) != 1)
|
||||
return new(false, "Prüfsumme der IBAN ist falsch");
|
||||
@ -203,10 +203,10 @@ namespace Elwig.Helpers {
|
||||
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)) {
|
||||
if ((v < 4 || v >= 6) && char.IsAsciiLetterOrDigit(ch)) {
|
||||
v++;
|
||||
text += char.ToUpper(ch);
|
||||
} else if (v >= 4 && v < 6 && char.IsAscii(ch) && char.IsLetter(ch)) {
|
||||
} else if (v >= 4 && v < 6 && char.IsAsciiLetter(ch)) {
|
||||
v++;
|
||||
text += char.ToUpper(ch);
|
||||
}
|
||||
@ -247,7 +247,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
// https://statistik.at/fileadmin/shared/QM/Standarddokumentationen/RW/std_r_land-forstw_register.pdf#page=41
|
||||
int s = 0, v = 0;
|
||||
int s = 0, v;
|
||||
for (int i = 0; i < 6; i++)
|
||||
s += (input.Text[i] - '0') * (7 - i);
|
||||
v = (11 - (s % 11)) % 10;
|
||||
@ -263,15 +263,15 @@ namespace Elwig.Helpers {
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v < 2 && char.IsAscii(ch) && char.IsLetter(ch)) {
|
||||
if (v < 2 && char.IsAsciiLetter(ch)) {
|
||||
v++;
|
||||
text += char.ToUpper(ch);
|
||||
} else if (v >= 2 && char.IsAscii(ch) && char.IsLetterOrDigit(ch)) {
|
||||
} else if (v >= 2 && char.IsAsciiLetterOrDigit(ch)) {
|
||||
if (text.StartsWith("AT")) {
|
||||
if (v == 2 && (ch == 'u' || ch == 'U')) {
|
||||
v++;
|
||||
text += 'U';
|
||||
} else if (v > 2 && char.IsDigit(ch)) {
|
||||
} else if (v > 2 && char.IsAsciiDigit(ch)) {
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace Elwig.Models {
|
||||
public virtual BillingAddr BillingAddress { get; private set; }
|
||||
|
||||
public int SearchScore(IEnumerable<string> keywords) {
|
||||
keywords = keywords.Where(s => s.Length >= 2 || (s.Length > 0 && s.All(c => char.IsDigit(c))));
|
||||
keywords = keywords.Where(s => s.Length >= 2 || (s.Length > 0 && s.All(c => char.IsAsciiDigit(c))));
|
||||
if (!keywords.Any())
|
||||
return 0;
|
||||
|
||||
|
Reference in New Issue
Block a user