Skip to content

Commit

Permalink
Merge pull request #134 from OnroerendErfgoed/bugfix/133_fix_rrn_vali…
Browse files Browse the repository at this point in the history
…dation

#133 fix rrn validation
  • Loading branch information
JonasGe authored Oct 11, 2023
2 parents 4699e12 + 9e03dd7 commit 82a4b5d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/custom-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ export const kboValidator = (value: string) => {

// Rijksregisternummer
export const rrnValidator = (value: string) => {
let valid = true;
let valid = false;
if (value) {
if (value.length < 11) {
value = value.replace(/\.|-/g, '').trim();
if (value.length !== 11) {
return false;
}
const checkDigit = parseInt(value.substring(value.length - 2), 10);
const modFunction = (nr: number) => 97 - (nr % 97);
const checkDigit = parseInt(value.substring(value.length - 2, value.length), 10);
let nrToCheck = parseInt(value.substring(0, 9), 10);
if (modFunction(nrToCheck) === checkDigit) {
const modFunctionNumber = modFunction(nrToCheck);
if (modFunctionNumber === checkDigit) {
return true;
}
nrToCheck = parseInt('2' + value.substring(0, 9), 10);
Expand Down

0 comments on commit 82a4b5d

Please sign in to comment.