aggiunta validazione codice fiscale con regex considerando anche omocodie

This commit is contained in:
Chai Botta 2021-01-22 19:05:43 +01:00
parent 6223e44534
commit b52d06c40d
3 changed files with 10 additions and 2 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "codice-fiscale-js",
"version": "2.3.6",
"version": "2.3.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -83,6 +83,9 @@ class CodiceFiscale {
if (cf.length !== 16) {
return false
}
if(! /^[A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1}$/.test(cf)){
return false;
}
const expectedCheckCode = codiceFiscale.charAt(15)
cf = codiceFiscale.slice(0, 15)
return CodiceFiscale.getCheckCode(cf).toUpperCase() === expectedCheckCode.toUpperCase();

View File

@ -443,3 +443,8 @@ describe("La classe Comune", ()=>{
})
})
let invalidCfis = "BLIPTR93MO4A674Q";
test('check invalid cfis by regex control', () => {
expect(CodiceFiscale.check(invalidCfis)).toEqual(false);
});