Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/validation/__tests__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ describe('validation-test', () => {
test('Accepts a special YTL-defined fake ssn (checkCode calculation is skipped)', () => {
assert.equal(validation.isSsnValid('210999-U097'), true)
})

test('Rejects impossible birthdates', () => {
assert.equal(validation.isSsnValid('888888-8883'), false)
})
})

describe('isFakeYtlSsn', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/validation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export function isSsnValid(ssn: string, ageSanityCheckForExams = false): boolean
const birthDateYear = Number(birthDate.slice(-2))
const currentYear = Number(new Date().getFullYear().toString().slice(-2))

const month = Number(birthDate.slice(2, 4))
const day = Number(birthDate.slice(0, 2))
if (month > 12) return false
if (day > 31) return false

// We don't want to always do these checks, for example if we validate
// data which is not related to current matricular exams
if (ageSanityCheckForExams) {
Expand Down
Loading