robertogallea / laravel-codicefiscale

Codice fiscale validation for php/laravel
MIT License
42 stars 16 forks source link

Regexp fails on Fiscal Code with Omocodia #23

Closed aureliomakaj closed 3 years ago

aureliomakaj commented 3 years ago

Hello. I have a fiscal code with omocodia, precisely L4L7 instead of L407 (Treviso). It gives me an exception during the check CheckForWrongCode when using the regular expression in the page.

The fiscal code is: XXXXXX##X##L4L7T ( X for letters, # for numbers).

The regexp fails in the bold part: /^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{2}[0-9a-z][a-z]$/i

A temporary solution I am using is: ^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9a-z]{3}[a-z]$/i

I think that all the indexes where we can find a char replaced with an omocodia code sould be replaced in the regexp from [0-9] to [0-9a-z].

Like: ^[a-z]{6}[0-9a-z]{2}[a-z][0-9a-z]{2}[a-z][0-9a-z]{3}[a-z]$/i

robertogallea commented 3 years ago

Hi, will you be available for submitting a PR with a test reproducing your issue?

Thank you!

aureliomakaj commented 3 years ago

I am sorry, I am not in an enviroment where I can fork the project and make a pull request. Also, I cannot write the fiscal code in my case for privacy reason, but I'll use a fake one.

I'll copy the code here. This one is correct:

$validator = new CodiceFiscale(); 
$validator->parse("MKJRLA80A01L407X")

This one fails:

$validator = new CodiceFiscale(); 
$validator->parse("MKJRLA80A01L4L7I")
robertogallea commented 3 years ago

Fixed in v1.7.1. Please confirm.

Thanks!

aureliomakaj commented 3 years ago

Thank you very much! Everything works fine now.