is-valid-account-number
Version:
Validates Norwegian bank account numbers
18 lines (12 loc) • 423 B
JavaScript
const checkdigit = require('checkdigit')
module.exports = function (accountNumber) {
if (!accountNumber) {
throw new Error('Missing required input: account number')
}
const accountnumber = accountNumber.toString().replace(/\D/g, '')
if (accountnumber.length !== 11) {
throw new Error('Wrong length. Account number must be 11 digits')
}
return checkdigit.mod11.isValid(accountnumber)
}