Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CreditCardAttribute.cs
Go to the documentation of this file.
2
3[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
5{
7 : base(DataType.CreditCard)
8 {
9 base.DefaultErrorMessage = System.SR.CreditCardAttribute_Invalid;
10 }
11
12 public override bool IsValid(object? value)
13 {
14 if (value == null)
15 {
16 return true;
17 }
18 if (!(value is string text))
19 {
20 return false;
21 }
22 string text2 = text.Replace("-", string.Empty);
23 text2 = text2.Replace(" ", string.Empty);
24 int num = 0;
25 bool flag = false;
26 for (int num2 = text2.Length - 1; num2 >= 0; num2--)
27 {
28 char c = text2[num2];
29 if (c < '0' || c > '9')
30 {
31 return false;
32 }
33 int num3 = (c - 48) * ((!flag) ? 1 : 2);
34 flag = !flag;
35 while (num3 > 0)
36 {
37 num += num3 % 10;
38 num3 /= 10;
39 }
40 }
41 return num % 10 == 0;
42 }
43}
static string CreditCardAttribute_Invalid
Definition SR.cs:26
Definition SR.cs:7