-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
148 lines (114 loc) · 4.74 KB
/
Program.cs
File metadata and controls
148 lines (114 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace IssuesTracker
{
class Program
{
static void Main(string[] args)
{
int input = 0;
string inputN1 = "";
do
{
Console.WriteLine("Simple IBAN trust method\n\t 1) IBAN Check\n\t 2) Quit\n\t ", input);
Console.Write("Enter Selection: ");
input = Convert.ToInt32(Console.ReadLine());
if (input == 2)
{
Console.WriteLine();
}
else if (input > 2)
{
Console.WriteLine("Invalid Menu Selection.\t Try Again");
}
else
{
Console.Write("Enter IBAN: ");
inputN1 = Valid(Console.ReadLine());
switch (input)
{
case 1:
//Console.WriteLine("\tResults: {0}", ValidateBankAccount(inputN1));
Console.WriteLine("\tResults: {0}", CheckIban(inputN1,true).ToString());
break;
}
Console.WriteLine("Press any key...");
Console.ReadKey();
Console.Clear();
}
}
while (input != 2 && input < 2);
Console.WriteLine("Press any key...");
Console.ReadKey();
} //End of main
public static string Valid(string validIban)
{
string validEntry = "";
bool result = string.IsNullOrEmpty(validIban);
if (result)
{
validEntry = "";
}
else
{
validEntry = validIban.ToString();
}
return validEntry;
}
public static StatusData CheckIban(string iban, bool cleanText)
{
if (cleanText) // remove empty space & convert all uppercase
iban = Regex.Replace(iban, @"\s", "").ToUpper();
if (Regex.IsMatch(iban, @"\W"))
return new StatusData(false, "The IBAN contains illegal characters.");
if (!Regex.IsMatch(iban, @"^\D\D\d\d.+"))
return new StatusData(false, "The structure of IBAN is wrong.");
if (Regex.IsMatch(iban, @"^\D\D00.+|^\D\D01.+|^\D\D99.+"))
return new StatusData(false, "The check digits of IBAN are wrong.");
string countryCode = iban.Substring(0, 2);
IbanData currentIbanData = (from id in IBANList()
where id.CountryCode == countryCode
select id).FirstOrDefault();
if (currentIbanData == null)
return new StatusData(false,
string.Format("IBAN for country {0} currently is not avaliable.",
countryCode));
if (iban.Length != currentIbanData.Lenght)
return new StatusData(false,
string.Format("The IBAN of {0} needs to be {1} characters long.",
countryCode, currentIbanData.Lenght));
if (!Regex.IsMatch(iban.Remove(0, 4), currentIbanData.RegexStructure))
return new StatusData(false,
"The country specific structure of IBAN is wrong.");
string modifiedIban = iban.ToUpper().Substring(4) + iban.Substring(0, 4);
modifiedIban = Regex.Replace(modifiedIban, @"\D",
m => ((int)m.Value[0] - 55).ToString());
int remainer = 0;
while (modifiedIban.Length >= 7)
{
remainer = int.Parse(remainer + modifiedIban.Substring(0, 7)) % 97;
modifiedIban = modifiedIban.Substring(7);
}
remainer = int.Parse(remainer + modifiedIban) % 97;
if (remainer != 1)
return new StatusData(false, "The IBAN is incorrect.");
return new StatusData(true, "The IBAN seems to be correct.");
}
public static List<IbanData> IBANList()
{
List<IbanData> newList = new List<IbanData>();
newList.Add(new IbanData("AD", 24,
@"\d{8}[a-zA-Z0-9]{12}", false,
"AD1200012030200359100100"));
//.... other countries
newList.Add(new IbanData("TR", 26,
@"\d{5}[a-zA-Z0-9]{17}", false,
"TR330006100519786457841326"));
return newList;
}
}
}