Skip to content

Commit

Permalink
Optimized RegEx to exclude reserved series
Browse files Browse the repository at this point in the history
  • Loading branch information
songyuew committed Jan 8, 2023
1 parent ffe041e commit 2a5b111
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/lib/isAbaRouting.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import assertString from './util/assertString';

// http://www.brainjar.com/js/validation/
const isRoutingReg = /^[0-9]{9}$/;

// series reserved for future use
// https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures
const isReservedReg = /^(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])$/;
// series reserved for future use are excluded
const 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}$/;

export default function isAbaRouting(str) {
assertString(str);
str = str.trim();

if (!isRoutingReg.test(str)) return false;
if (isReservedReg.test(str.slice(0, 2))) return false;

let checkSumVal = 0;
for (let i = 0; i < str.length; i++) {
Expand Down

0 comments on commit 2a5b111

Please sign in to comment.