From 2a5b1113e9bd23ea54d2c1fb8c5b91d0181e579d Mon Sep 17 00:00:00 2001 From: Songyue Wang Date: Sun, 8 Jan 2023 16:46:07 +0800 Subject: [PATCH] Optimized RegEx to exclude reserved series --- src/lib/isAbaRouting.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib/isAbaRouting.js b/src/lib/isAbaRouting.js index ec5b04f1a..7cff0def7 100644 --- a/src/lib/isAbaRouting.js +++ b/src/lib/isAbaRouting.js @@ -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++) {