isAbaRouting.js 993 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isAbaRouting;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. // http://www.brainjar.com/js/validation/
  9. // https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures
  10. // series reserved for future use are excluded
  11. var isRoutingReg = /^(?!(1[3-9])|(20)|(3[3-9])|(4[0-9])|(5[0-9])|(60)|(7[3-9])|(8[1-9])|(9[0-2])|(9[3-9]))[0-9]{9}$/;
  12. function isAbaRouting(str) {
  13. (0, _assertString.default)(str);
  14. if (!isRoutingReg.test(str)) return false;
  15. var checkSumVal = 0;
  16. for (var i = 0; i < str.length; i++) {
  17. if (i % 3 === 0) checkSumVal += str[i] * 3;else if (i % 3 === 1) checkSumVal += str[i] * 7;else checkSumVal += str[i] * 1;
  18. }
  19. return checkSumVal % 10 === 0;
  20. }
  21. module.exports = exports.default;
  22. module.exports.default = exports.default;