Skip to content

Commit

Permalink
Merge pull request #16 from svsticky/IBAN
Browse files Browse the repository at this point in the history
Implemented 11-test in IBAN checking
  • Loading branch information
MarcelvLaar authored Nov 11, 2024
2 parents 95eadf8 + 425bd58 commit eaf63e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/plugins/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const EN: Locale = {
hints: {
name: "Treasurer",
email: "{'[email protected]'}",
iban: "NL13TEST0123456789",
iban: "GB94BARC10201530093459",
value: "19,19",
what: "Digging Machine",
commission: "The board, obviously!"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/plugins/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const NL: Locale = {
hints: {
name: "Penningmeester",
email: "{'[email protected]'}",
iban: "NL13TEST0123456789",
iban: "GB94BARC10201530093459",
value: "19,19",
what: "Graafmachine",
commission: "Bestuur, lul!"
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ interface Data {
}
}
function checkIBAN(iban: string): boolean {
if (!/([a-zA-Z]{2}[0-9]{2})([a-zA-Z]{4}[0-9]{10})/.test(iban)){ // Check if the general format is OK
return false;
}
const numericIban = (iban.slice(4) + iban.slice(0, 4)).replace(/[A-Z]/g, char => (char.charCodeAt(0) - 55).toString()); // 11-test
const remainder = numericIban.split('').reduce((acc, digit) => (acc + digit) % 97, 0);
return remainder === 1;
}
export default defineComponent({
components: {MaterialBanner},
data(): Data {
Expand All @@ -158,7 +167,7 @@ export default defineComponent({
],
iban: [
v => !!v || this.$t("home.form.rules.required"),
v => /([a-zA-Z]{2}[0-9]{2})([a-zA-Z]{4}[0-9]{10})/.test(v) || this.$t("home.form.rules.ibanInvalid")
v => checkIBAN(v) || this.$t("home.form.rules.ibanInvalid")
],
email: [
v => !!v || this.$t("home.form.rules.required"),
Expand Down

0 comments on commit eaf63e5

Please sign in to comment.