Skip to content

Commit

Permalink
improve nirValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
VachetVirginie committed Oct 22, 2024
1 parent a9b795b commit 65a2cd8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ export function checkNIR(nir: string): boolean {

const nirRegex = new RegExp(
'^' +
'(?<sexe>[12])' +
'(?<sexe>[1-4]|7|8)' +
'(?<anneeNaissance>\\d{2})' +
'(?<moisNaissance>0[1-9]|1[0-2]|[2-9][0-9])' +
'(?<departementNaissance>\\d{2}|2A|2B)' +
'(?<moisNaissance>0[1-9]|1[0-2]|2[0-9]|3[0-9]|4[0-2])' +
'(?<departementNaissance>\\d{2}|2A|2B|96|97\\d|98\\d)' +
'(?<communeNaissance>\\d{3})' +
'(?<rangInscription>\\d{3})' +
'(?<cle>9[0-7]|[0-8]\\d)?' +
'(?<cle>[0-9]{2})?' +
'$',
'i'
);

return nirRegex.test(nir);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest'

describe('NIR Validations', () => {
it('returns true for valid NIR', () => {
expect(checkNIR('1234567890123')).toBe(true);
expect(checkNIR('175039720123594')).toBe(true);
});

it('returns false for invalid NIR', () => {
Expand Down

0 comments on commit 65a2cd8

Please sign in to comment.