Skip to content

Commit 3ab5c1f

Browse files
committed
Merge pull request #7 from uphold/enhancement/add-accountnumber-sortcode-length-validation
Add accountNumber and sortCode length validation
2 parents e0c1eec + 8276bb8 commit 3ab5c1f

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ export default class UkModulusChecking {
199199
*/
200200

201201
isValid() {
202+
if (this.accountNumber.length < 6 || this.accountNumber.length > 10 || this.sortCode.length !== 6) {
203+
return false;
204+
}
205+
202206
const checks = this.getSortCodeChecks();
203207

204208
// If no range is found that contains the sorting code, there is no modulus check that can be performed.

test/index_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ const accounts = {
5252

5353
describe('UkModulusChecking', () => {
5454
describe('isValid()', () => {
55+
it('should return false if account number length is less than 6', () => {
56+
new UkModulusChecking({ accountNumber: '12345', sortCode: '123456' }).isValid().should.be.false();
57+
});
58+
59+
it('should return false if account number length is greater than 10', () => {
60+
new UkModulusChecking({ accountNumber: '12345678901', sortCode: '123456' }).isValid().should.be.false();
61+
});
62+
63+
it('should return false if sort code length is not 6', () => {
64+
new UkModulusChecking({ accountNumber: '12345789', sortCode: '12345' }).isValid().should.be.false();
65+
});
66+
5567
accounts.invalid.forEach((account) => {
5668
it(`should return false if sort code is ${account.sortCode} and account number is ${account.accountNumber}`, () => {
5769
new UkModulusChecking({ accountNumber: account.accountNumber, sortCode: account.sortCode }).isValid().should.be.false();

0 commit comments

Comments
 (0)