Skip to content

Commit 0ac4ad2

Browse files
authored
Merge pull request #174 from brianlu2610/us-ssn-fix
fix(us-ssn-generation): added checks for valid SSN generation
2 parents 64fd050 + 6cbc009 commit 0ac4ad2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

api/.nextRelease/data/US/inject.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ module.exports = (inc, contents) => {
66

77
include(inc, contents, 'phone', '(' + random(4, 1) + random(3, 2) + ') ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
88
include(inc, contents, 'cell', '(' + random(4, 1) + random(3, 2) + ') ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
9-
include(inc, contents, 'id', {
10-
name: 'SSN',
11-
value: random(3, 3) + '-' + random(3, 2) + '-' + random(3, 4)
9+
include(inc, contents, 'id', () => {
10+
const checkSSN = (ssn) => {
11+
const regex = new RegExp("^(?!219-09-9999|078-05-1120)(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$");
12+
return regex.test(ssn);
13+
};
14+
const genSSN = () => {
15+
let ssn = random(3, 3) + '-' + random(3, 2) + '-' + random(3, 4);
16+
while(!checkSSN(ssn)){
17+
ssn = random(3, 3) + '-' + random(3, 2) + '-' + random(3, 4);
18+
}
19+
return ssn;
20+
};
21+
contents.id = {
22+
name: 'SSN',
23+
value: genSSN()
24+
}
1225
});
1326
include(inc, contents, 'picture', pic);
1427
};

0 commit comments

Comments
 (0)