Skip to content

Instantly share code, notes, and snippets.

@rj76
Created October 2, 2021 09:50
Show Gist options
  • Save rj76/63977d82ae02a8780ebc62b5e6b905b0 to your computer and use it in GitHub Desktop.
Save rj76/63977d82ae02a8780ebc62b5e6b905b0 to your computer and use it in GitHub Desktop.
BSN checker
bool isNumeric(String? s) {
if(s == null) {
return false;
}
return double.tryParse(s) != null;
}
bool isValidBsn(String bsn) {
/*
Validator based on a variation of the Dutch check-digit validation used for checking IBAN.
This variation is used for BSN.
For more information visit https://nl.wikipedia.org/wiki/Elfproef#Burgerservicenummer
:param bsn: customer service number (BSN), must be 9 digits
:return: true if valid, false if invalid
*/
int bsnLen = bsn.length;
if (bsnLen != 9 || !isNumeric(bsn)) {
return false;
}
int total = 0;
for (int index=0; index<8; index++) {
String t = bsn[index];
total += int.parse(t) * (9 - index);
}
int lastNumber = int.parse(bsn[8]);
// Validate if the remainder of the total divided by 11 is equal to the last number in the BSN
if (total % 11 != lastNumber) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment