-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
300 lines (276 loc) · 12.7 KB
/
index.html
File metadata and controls
300 lines (276 loc) · 12.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<meta name="author" content="Itamar Junior" />
<meta name="contact" content="hello@itjunior.dev" />
<meta name="description"
content="Use this PPSN Validator to easily verify the validity of Irish Personal Public Service Numbers. Enter any PPSN to check if it meets the required criteria." />
<meta name="keywords"
content="PPSN, Validator, Ireland PPSN, PPSN check, validate PPSN, Irish tax number validation" />
<meta name="robots" content="index, follow" />
<meta name="language" content="English" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="expires" content="0" />
<title>
PPSN Validator - Validate Irish Personal Public Service Numbers
</title>
<script>
// PPSN validation script
function validatePPSN(ppsn) {
// Remove any spaces or hyphens from the input
ppsn = ppsn.replace(/\s+/g, "").toUpperCase();
// Validate the format using a regular expression
const ppsnFormat = /^[0-9]{7}[A-W][ABWXTZ]?$/;
if (!ppsnFormat.test(ppsn)) {
return false;
}
// Extract the digits and characters
const digits = ppsn.slice(0, 7).split("").map(Number);
const checkChar = ppsn.charAt(7);
const secondChar = ppsn.length === 9 ? ppsn.charAt(8) : "";
// Calculate the sum using the weighted digits
const weights = [8, 7, 6, 5, 4, 3, 2];
let sum = 0;
for (let i = 0; i < 7; i++) {
sum += digits[i] * weights[i];
}
// Calculate the check character value
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const checkValue = alphabet.indexOf(checkChar) + 1;
// If there's a 9th character, add its weighted value
if (secondChar) {
const secondCharValue = alphabet.indexOf(secondChar) + 1;
sum += secondCharValue * 9;
}
// Calculate the modulus 23
const remainder = sum % 23;
// Determine the expected check character
const expectedCheckChar =
remainder === 0 ? "W" : alphabet[remainder - 1];
// Validate the check character
if (checkChar !== expectedCheckChar) {
return false;
}
// Validate the second character if it exists
if (
secondChar &&
!["A", "B", "W", "X", "T", "Z"].includes(secondChar)
) {
return false;
}
// If all checks pass, return true
return true;
}
// Form validation handler
function validateForm(event) {
event.preventDefault(); // Prevent form submission and page reload
const ppsnInput = document.getElementById("ppsn").value;
if (!validatePPSN(ppsnInput)) {
document.getElementById("invalidatedPPSN").innerHTML = ppsnInput;
document.querySelector("form").classList.add("hidden");
document.getElementById("isInvalid").classList.remove("hidden");
document.getElementById("isInvalid").scrollIntoView({ behavior: "smooth" });
return false;
}
document.getElementById("validatedPPSN").innerHTML = ppsnInput;
document.querySelector("form").classList.add("hidden");
document.getElementById("isValid").classList.remove("hidden");
document.getElementById("isValid").scrollIntoView({ behavior: "smooth" });
return false; // Prevent the form from submitting
}
function resetValidation() {
document.querySelector("form").classList.remove("hidden");
document.getElementById("isValid").classList.add("hidden");
document.getElementById("isInvalid").classList.add("hidden");
document.getElementById("ppsn").value = ""; // Clear the input field
}
// Function to set a cookie
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
// Function to get a cookie
function getCookie(name) {
const decodedCookie = decodeURIComponent(document.cookie);
const cookieArray = decodedCookie.split(';');
name = name + "=";
for (let i = 0; i < cookieArray.length; i++) {
let cookie = cookieArray[i];
while (cookie.charAt(0) == ' ') {
cookie = cookie.substring(1);
}
if (cookie.indexOf(name) == 0) {
return cookie.substring(name.length, cookie.length);
}
}
return "";
}
// Function to close the disclaimer and set a cookie
function closeDisclaimer() {
document.getElementById("disclaimer").style.display = "none";
setCookie("disclaimerClosed", "true", 30); // Remember for 30 days
}
// Check if the disclaimer has been closed before
window.onload = function () {
if (getCookie("disclaimerClosed") === "true") {
document.getElementById("disclaimer").style.display = "none";
}
};
</script>
</head>
<body class="dark:bg-gray-800">
<div class="dark:bg-gray-800">
<div class="dark:bg-transparent">
<div class="mx-auto flex flex-col items-center py-12 sm:py-24">
<div class="w-11/12 sm:w-2/3 lg:flex justify-center items-center flex-col mb-5 sm:mb-10">
<h1
class="text-4xl sm:text-5xl md:text-5xl lg:text-5xl xl:text-6xl text-center text-gray-800 dark:text-white font-black leading-10">
Validate
<span class="text-green-800 dark:text-green-500">Irish PPS Number</span>
</h1>
<p class="mt-5 sm:mt-10 lg:w-10/12 text-gray-600 dark:text-gray-300 font-normal text-center text-xl">
A PPSN is a 9-digit number issued by the Government of Ireland. It
is used for tax and social welfare purposes. Enter a PPSN below to
validate it.
</p>
</div>
<form onsubmit="return validateForm(event)">
<div class="flex rounded-md w-full">
<label for="ppsn" class="sr-only">Enter PPS Number:</label>
<input type="text" id="ppsn" name="ppsn" required
class="w-full p-3 rounded-md rounded-r-none border border-2 border-gray-300 placeholder-current dark:bg-gray-500 dark:text-gray-300 dark:border-none"
placeholder="Enter PPS Number" />
<button type="submit"
class="inline-flex items-center gap-2 bg-green-700 text-white text-lg font-semibold py-3 px-6 rounded-r-md">
<span>Validate</span>
</button>
</div>
</form>
<div class="mx-auto flex flex-col items-center py-12 sm:py-24 hidden" id="isValid">
<div class="flex rounded-md w-full">
<div class="rounded-md bg-green-50 p-4 mt-5">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-green-800">
This is a valid PPS Number
</h3>
<div class="mt-2 text-sm text-green-700">
<p>
The validated PPS Number is:</br>
<span id="validatedPPSN"></span>
</p>
</div>
<div class="mt-4">
<div class="grid justify-end">
<button type="button" onclick="resetValidation()"
class="ml-3 rounded-md bg-green-50 px-2 py-1.5 text-sm font-medium text-green-800 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2 focus:ring-offset-green-50">
New Validation
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="mx-auto flex flex-col items-center py-12 sm:py-24 hidden" id="isInvalid">
<div class="flex rounded-md w-full">
<div class="rounded-md bg-red-50 p-4 mt-5">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">
Invalid PPS Number
</h3>
<div class="mt-2 text-sm text-red-700">
<p>
The PPS Number you entered:
<span id="invalidatedPPSN"></span></br>
Is not a valid PPS Number. Please try again.
</p>
</div>
<div class="mt-4">
<div class="grid justify-end">
<button type="button" onclick="resetValidation()"
class="ml-3 rounded-md bg-red-50 px-2 py-1.5 text-sm font-medium text-red-800 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-red-600 focus:ring-offset-2 focus:ring-offset-red-50">
Try Again
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer content -->
<footer class="bg-white rounded-lg shadow m-4 dark:bg-gray-800 dark:border-gray-700 fixed bottom-0 left-0 right-0">
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-between">
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400">© 2024 Itamar Junior -
<a href="https://itjunior.dev" class="hover:underline">itjunior.dev</a>.
</span>
<ul class="flex flex-wrap items-center mt-3 text-sm font-medium text-gray-500 dark:text-gray-400 sm:mt-0">
<li>
<a href="https://github.com/codeitamarjr/IE-PPSN-Validator" class="hover:underline m-2">GitHub Project
Page</a>
</li>
<li>
<a href="mailto:hello@itjunior.dev" class="hover:underline">Contact</a>
</li>
</ul>
</div>
</footer>
<div aria-live="assertive" id="disclaimer"
class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6">
<div class="flex w-full flex-col items-center space-y-4 sm:items-end">
<div
class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-white shadow-lg ring-1 ring-black ring-opacity-5 dark:bg-gray-700 dark:ring-gray-600">
<div class="p-4">
<div class="flex items-center">
<div class="w-full">
<p class="text-sm font-medium text-gray-900 dark:text-white">Disclaimer</p>
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300">
This software is not affiliated with the Government of Ireland. It is a free tool to validate PPS
Numbers.
</p>
<p class="mt-1 text-sm text-gray-500 dark:text-gray-300">
The validation algorithm runs locally and no data is stored in any server.
</p>
</div>
<div class="ml-4 flex flex-shrink-0">
<button type="button" onclick="closeDisclaimer()"
class="inline-flex rounded-md bg-white dark:bg-gray-800 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
<span class="sr-only">Close</span>
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>