Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PhoneAttribute.cs
Go to the documentation of this file.
2
3[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
4public sealed class PhoneAttribute : DataTypeAttribute
5{
8 {
9 base.DefaultErrorMessage = System.SR.PhoneAttribute_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 potentialPhoneNumber = text.Replace("+", string.Empty).TrimEnd();
23 potentialPhoneNumber = RemoveExtension(potentialPhoneNumber);
24 bool flag = false;
25 string text2 = potentialPhoneNumber;
26 foreach (char c in text2)
27 {
28 if (char.IsDigit(c))
29 {
30 flag = true;
31 break;
32 }
33 }
34 if (!flag)
35 {
36 return false;
37 }
38 string text3 = potentialPhoneNumber;
39 foreach (char c2 in text3)
40 {
41 if (!char.IsDigit(c2) && !char.IsWhiteSpace(c2) && "-.()".IndexOf(c2) == -1)
42 {
43 return false;
44 }
45 }
46 return true;
47 }
48
49 private static string RemoveExtension(string potentialPhoneNumber)
50 {
51 int num = potentialPhoneNumber.LastIndexOf("ext.", StringComparison.OrdinalIgnoreCase);
52 if (num >= 0)
53 {
54 string potentialExtension = potentialPhoneNumber.Substring(num + "ext.".Length);
55 if (MatchesExtension(potentialExtension))
56 {
57 return potentialPhoneNumber.Substring(0, num);
58 }
59 }
60 num = potentialPhoneNumber.LastIndexOf("ext", StringComparison.OrdinalIgnoreCase);
61 if (num >= 0)
62 {
63 string potentialExtension2 = potentialPhoneNumber.Substring(num + "ext".Length);
64 if (MatchesExtension(potentialExtension2))
65 {
66 return potentialPhoneNumber.Substring(0, num);
67 }
68 }
69 num = potentialPhoneNumber.LastIndexOf("x", StringComparison.OrdinalIgnoreCase);
70 if (num >= 0)
71 {
72 string potentialExtension3 = potentialPhoneNumber.Substring(num + "x".Length);
73 if (MatchesExtension(potentialExtension3))
74 {
75 return potentialPhoneNumber.Substring(0, num);
76 }
77 }
78 return potentialPhoneNumber;
79 }
80
81 private static bool MatchesExtension(string potentialExtension)
82 {
83 potentialExtension = potentialExtension.TrimStart();
84 if (potentialExtension.Length == 0)
85 {
86 return false;
87 }
88 string text = potentialExtension;
89 foreach (char c in text)
90 {
91 if (!char.IsDigit(c))
92 {
93 return false;
94 }
95 }
96 return true;
97 }
98}
static bool MatchesExtension(string potentialExtension)
static string RemoveExtension(string potentialPhoneNumber)
static string PhoneAttribute_Invalid
Definition SR.cs:70
Definition SR.cs:7