-
Notifications
You must be signed in to change notification settings - Fork 12
/
functions_validate.js
executable file
·150 lines (128 loc) · 4.92 KB
/
functions_validate.js
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
149
150
function validateName(field) {
if (field == "") return "Please enter a Name.\n\n"
return ""
}
function validateDob(field) {
if (field == "") return "Please enter a Date of Birth.\n\n"
else if (/[^0-9.]/.test(field)) return "DoB is invalid. Format must be: DD.MM.YYYY\n\n"
else if (field.length != 10) return "DoB is invalid. Format must be: DD.MM.YYYY\n\n"
else if (!(field.indexOf(".") == 2)) return "DoB is invalid. Format must be: DD.MM.YYYY\n\n"
return ""
}
function validateAddress(field) {
if (field == "") return "Please enter an Address.\n\n"
return ""
}
function validatePhone(field) {
if (field == "") return "Please enter a Phone Number.\n\n"
else if (/[^0-9+-/ ]/.test(field)) return "The Phone Number is invalid.\n\n"
return ""
}
function validateEmail(field){
if (field != ""){
if (!((field.indexOf(".") > 0) && (field.indexOf("@") > 0)) || /[^a-zA-Z0-9.@_-]/.test(field)) return "The Email address is invalid.\n\n"
}
return ""
}
function validateReceipt(field) {
if (field == "") return "Please specify the Receipt Number.\n\n"
return ""
}
function validateSlip(field) {
if (field == "") return "Please specify the Slip Number.\n\n"
return ""
}
function validateAmount(field) {
if (field == "") return "Please enter an Amount.\n\n"
if (field <= 0) return "Amount cannot be Zero or below.\n\n"
return ""
}
function validateOverdraft(field, balance, wd_fee, minsavbal, fixed){
fieldTotal = (field * 1) + (wd_fee * 1)
balanceMin = (balance * 1) + (minsavbal * -1)
balanceFix = (balance * 1) + (fixed * -1)
if (fieldTotal > balanceMin) return "Withdrawal not permitted.\nMinimum savings balance is " + minsavbal + "."
if (fieldTotal > balanceFix) return "Withdrawal not permitted.\nFixed deposits on this account are " + fixed + "."
return ""
}
function validateRecipient(field) {
if (field == "") return "Please enter a Recipient.\n\n"
return ""
}
function validateVoucher(field) {
if (field == "") return "Please specify a Voucher Number.\n\n"
return ""
}
function validateDate(field) {
if (field == "") return "Please enter a Date.\n\n"
else if (/[^0-9.]/.test(field)) return "Date is invalid. Format must be: DD.MM.YYYY\n\n"
else if (field.length != 10) return "Date is invalid. Format must be: DD.MM.YYYY\n\n"
else if (!(field.indexOf(".") == 2)) return "Date is invalid. Format must be: DD.MM.YYYY\n\n"
return ""
}
function validatePrincipal(field) {
if (field == "") return "Please enter a Principal Amount.\n\n"
return ""
}
function validateInstalment(field) {
if (field == "") return "Please enter a number of Instalments.\n\n"
return ""
}
function validateInterest(field) {
if (field == "") return "Please enter a monthly Interest Rate.\n\n"
return ""
}
function validateRepaystart(field) {
if (field == "") return "Please enter a Repay Start Date.\n\n"
else if (/[^0-9.]/.test(field)) return "Start Date is invalid. Format must be: DD.MM.YYYY\n\n"
else if (field.length != 10) return "Start Date is invalid. Format must be: DD.MM.YYYY\n\n"
else if (!(field.indexOf(".") == 2)) return "Start Date is invalid. Format must be: DD.MM.YYYY\n\n"
return ""
}
function validatePurpose(field) {
if (field == "") return "Please enter a Purpose for the loan.\n\n"
return ""
}
function validateSecurity(field) {
if (field == "") return "Please enter at least one Security.\n\n"
return ""
}
function validateGuarantors(field1) {
returnstring = ""
if (field1 == "") returnstring = "Please choose first Guarantor.\n\n"
// // if (field2 == "") returnstring += "Please choose second Guarantor.\n\n"
// // if (field3 == "") returnstring += "Please choose third Guarantor.\n\n"
// // else if (field1 == field2 || field1 == field3 || field2 == field3) returnstring += "Guarantors must be three distinct customers.\n\n"
return returnstring
}
function validateUser(field, usernames, user_id) {
if (field == "") return "Please enter a Username.\n\n"
if (user_id == 0){
for (i = 0, len = usernames.length; i < len; i++){
if (usernames[i] == field) return "Username already exists.\nPlease choose a different username.\n\n"
}
}
return ""
}
function validatePw(pw, pw_conf) {
if (pw == "") return "Please enter a password.\n\n"
if (pw.length < 6) return "Password is too short. Please use at least 6 characters.\n\n"
if (pw_conf == "") return "Please repeat password for confirmation.\n\n"
if (pw != pw_conf) return "Passwords do not match.\n\n"
return ""
}
function validateUsergroup(field, ugroupnames, ugroup_id) {
if (field == "") return "Please enter a Usergroup name.\n\n"
if (ugroup_id == 0){
for (i = 0, len = ugroupnames.length; i < len; i++){
if (ugroupnames[i] == field) return "Usergroup name already exists.\nPlease choose a different usergroup name.\n\n"
}
}
return ""
}
function validateEmployee(field, employees, empl_current) {
for (i = 0, len = employees.length; i < len; i++){
if (employees[i] == field && field != empl_current) return "Employee already associated with another username.\n\n"
}
return ""
}