-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidation.cs
121 lines (112 loc) · 2.7 KB
/
Validation.cs
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
namespace BankingApp;
public class Validation
{
/// <summary>
/// Validates the email address
/// </summary>
/// <returns></returns>
public static string validateEmail()
{
Console.Write("Enter Email: ");
string email = Console.ReadLine().Trim().ToLower();
if (email.Contains("@") && email.Contains("."))
{
return email;
}
else
{
Console.WriteLine("Invalid Email");
return validateEmail();
}
}
/// <summary>
/// Validates the phone number
/// </summary>
/// <returns></returns>
public static string validatePhone()
{
Console.Write("Enter Phone Number: ");
string phone = Console.ReadLine().Trim();
if (phone.Length == 11)
{
return phone;
}
else
{
Console.WriteLine("Phone Number must be 11 digits");
return validatePhone();
}
}
/// <summary>
/// Validates the PIN
/// </summary>
/// <returns></returns>
public static string validatePIN()
{
Console.Write("Enter PIN: ");
string PIN = Console.ReadLine().Trim();
if (PIN.Length == 4)
{
return PIN;
}
else
{
Console.WriteLine("PIN must be 4 digits");
return validatePIN();
}
}
/// <summary>
/// Validates the name
/// </summary>
/// <returns></returns>
public static string validateName()
{
Console.Write("Enter Name: ");
string name = Console.ReadLine().Trim();
if (name.Length > 0)
{
return name;
}
else
{
Console.WriteLine("Invalid Name");
return validateName();
}
}
/// <summary>
/// Validates the username
/// </summary>
/// <returns></returns>
public static string validateUsername()
{
Console.Write("Enter Username: ");
string username = Console.ReadLine().Trim().ToLower();
if (username.Length > 0)
{
return username;
}
else
{
Console.WriteLine("Invalid Username");
return validateUsername();
}
}
/// <summary>
/// Validates the amount
/// </summary>
/// <returns></returns>
public static double validateAmount()
{
Console.Write("Enter Amount: ");
try
{
double amount = Double.Parse(Console.ReadLine().Trim());
return amount;
}
catch (Exception e)
{
Console.WriteLine("Invalid Amount");
return validateAmount();
}
}
}