Italian regexes¶
Python regexes for Italian identifiers, with checksum validation: codice fiscale, partita IVA, IBAN, carta d'identità, passport, targa and phone numbers.
21 regexes, from regular_regexes/it/regexes.json, called as rre.it.<name>(text).
Personal numbers (1) · Identity documents (4) · Companies and tax (3) · Banking and payments (2) · Phones and SIM cards (6) · Places and addresses (2) · Vehicles, ships and parcels (2) · Justice and police (1)
Personal numbers¶
| function | checksum validator |
|---|---|
rre.it.codice_fiscale |
it_codice_fiscale |
codice_fiscale¶
Italian tax code (codice fiscale): 16 letters and digits from surname, name, date and place of birth, like RSSMRA85T10A562S, also with omocodia letters in place of digits, in capitals or lowercase.
rre.it.codice_fiscale(text)
(?i)\b[A-Z]{6}[\dLMNPQRSTUV]{2}[ABCDEHLMPRST][\dLMNPQRSTUV]{2}[A-Z][\dLMNPQRSTUV]{3}[A-Z]\b
Matches are checked with it_codice_fiscale; one that fails it is dropped.
Identity documents¶
| function | checksum validator |
|---|---|
rre.it.id_card_number |
|
rre.it.mrz_id_card |
mrz_td1 |
rre.it.mrz_passport |
mrz_td3 |
rre.it.passport_number |
id_card_number¶
Italian electronic identity card number (carta d'identità elettronica, CIE): two letters, five digits and two letters, like CA00000AA.
rre.it.id_card_number(text)
\b[A-Z]{2}\d{5}[A-Z]{2}\b
mrz_id_card¶
Machine-readable zone (MRZ) of an Italian identity card (CIE), first line (ICAO TD1): 30 characters with ITA as issuing country, like CIITACA00000AA4<<<<<<<<<<<<<<<.
rre.it.mrz_id_card(text)
(?<![A-Z0-9<])[IAC][A-Z<]ITA[A-Z0-9<]{25}(?![A-Z0-9<])
Matches are checked with mrz_td1; one that fails it is dropped.
mrz_passport¶
Machine-readable zone (MRZ) of an Italian passport, second line (ICAO TD3): 44 characters with the passport number, ITA as nationality, date of birth, sex and expiry date.
rre.it.mrz_passport(text)
(?<![A-Z0-9<])[A-Z0-9<]{9}\dITA\d{6}\d[MFX<]\d{6}\d[A-Z0-9<]{14}[\d<]\d(?![A-Z0-9<])
Matches are checked with mrz_td3; one that fails it is dropped.
passport_number¶
Italian passport number (numero di passaporto): two capital letters and seven digits, like YA1234567 or YB7654321.
rre.it.passport_number(text)
\b[A-Z]{2}\d{7}\b
Companies and tax¶
| function | checksum validator |
|---|---|
rre.it.company_name |
|
rre.it.partita_iva |
it_partita_iva |
rre.it.vat_number |
it_partita_iva |
company_name¶
Italian company name (ragione sociale): capitalized words, with di, e, del or della between them (also Rossi e figli), followed by S.r.l., S.r.l.s., S.p.A., S.a.s., S.n.c., S.c.a.r.l. or Soc. Coop., like Fiat S.p.A..
rre.it.company_name(text)
\b[A-Z][\w&'.-]{0,40}(?:\s(?:(?:di|e|del|della|delle|dei|degli|dello)\s)?(?:[A-Z0-9][\w&'.-]{0,40}|&|figli)){0,6}?,?\s(?i:s\.?r\.?l\.?(?:s\.?)?|s\.?p\.?a\.?|s\.?a\.?s\.?|s\.?n\.?c\.?|s\.?c\.?(?:a\.?)?r\.?l\.?|soc\.?\s?coop\.?)(?!\w)
partita_iva¶
Italian VAT number (partita IVA) without the IT prefix: 11 digits on their own, like 07643520567 or 00743110157.
rre.it.partita_iva(text)
\b\d{11}\b
Matches are checked with it_partita_iva; one that fails it is dropped.
vat_number¶
Italian VAT number (partita IVA) with its prefix: IT and 11 digits, with or without a space, like IT07643520567 or IT 00743110157.
rre.it.vat_number(text)
\bIT\s?\d{11}\b
Matches are checked with it_partita_iva; one that fails it is dropped.
Banking and payments¶
| function | checksum validator |
|---|---|
rre.it.bic |
|
rre.it.iban |
iban |
bic¶
BIC (SWIFT code) of an Italian bank: four letters, IT and two letters or digits, with an optional three-character branch code, like UNCRITMM or BCITITMMXXX.
rre.it.bic(text)
\b[A-Z]{4}IT[A-Z0-9]{2}(?:[A-Z0-9]{3})?\b
iban¶
Italian IBAN: IT, two check digits, the CIN letter and 22 digits and letters (ABI, CAB, account number), with or without spaces, like IT60 X054 2811 1010 0000 0123 456.
rre.it.iban(text)
\bIT ?\d{2} ?[A-Z](?: ?[0-9A-Z]){22}\b
Matches are checked with iban; one that fails it is dropped.
Phones and SIM cards¶
| function | checksum validator |
|---|---|
rre.it.iccid |
luhn |
rre.it.imsi |
|
rre.it.mobile_number |
phone |
rre.it.msisdn |
phone |
rre.it.phone_number |
phone |
rre.it.premium_number |
phone |
iccid¶
SIM card number (ICCID) of an Italian SIM: 8939 followed by 14 to 16 digits, without spaces, like 8939011234567890127.
rre.it.iccid(text)
\b8939\d{14,16}\b
Matches are checked with luhn; one that fails it is dropped.
imsi¶
IMSI (subscriber identity on a SIM) of an Italian network: mobile country code 222 and 12 more digits, 15 in all, like 222011234567890.
rre.it.imsi(text)
\b222\d{12}\b
mobile_number¶
Italian mobile number (cellulare): 3 and eight or nine more digits, with spaces, dots, slashes or dashes, and with or without +39 or 0039, like 312 345 6789; only valid mobile numbers.
rre.it.mobile_number(text)
(?:(?:\+|\b00)39[\s.-]?|(?<![\w+€])(?<!\d[\s./-])(?<!€ ))3[1-9]\d(?:[\s/.-]?\d){6,7}(?![\s.-]?\d|,\d)
Matches are checked with phone (regions IT VA, kind mobile); one that fails it is dropped.
msisdn¶
Italian mobile number in MSISDN form, as in telecom records: 39 and the mobile number, 11 or 12 digits like 393123456789; only valid Italian mobile numbers.
rre.it.msisdn(text)
(?<!\+)\b393[1-9]\d{7,8}\b
Matches are checked with phone (regions IT VA, kind msisdn); one that fails it is dropped.
phone_number¶
Italian phone number (numero di telefono): landlines with 0 and the area code, like 02 1234 5678, (02) 1234 5678 or 0571 123456, and 3xx mobiles, with or without +39 or 0039; only valid numbers.
rre.it.phone_number(text)
(?:(?:\+|\b00)39[\s.-]?|(?<![\w+€])(?<!\d[\s./-])(?<!€ )(?<![A-Z]{2}\d\d [A-Z]{4} )(?!\d{11}))(?:\(?0\d{1,3}\)?[\s/.-]?\d{3,4}[\s-]?\d{2,4}|3[1-9]\d(?:[\s/.-]?\d){6,7})(?![\s.-]?\d|,\d|[A-Za-z]|/\d)
Matches are checked with phone (regions IT VA); one that fails it is dropped.
premium_number¶
Italian premium-rate number: 899 and six digits, or 894 and 895 numbers of 8 to 10 digits, with or without spaces, like 899 123 456; only valid Italian numbers.
rre.it.premium_number(text)
(?<![\w+])(?<!\d[\s./-])(?:899(?:[\s.-]?\d){6}|89[45](?:[\s.-]?\d){5,7})(?![\s.-]?\d)
Matches are checked with phone (regions IT VA, kind premium); one that fails it is dropped.
Places and addresses¶
| function | checksum validator |
|---|---|
rre.it.postal_code_city |
|
rre.it.street_address |
postal_code_city¶
Italian postal code (CAP, codice di avviamento postale) and comune: five digits and the place name, with the province in brackets if given, like 20121 Milano (MI).
rre.it.postal_code_city(text)
\b\d{5}\s(?!EUR|Euro|USD|CHF|GBP|Lire)[A-Z][\w'-]*(?:\s(?:(?:di|del|della|delle|dei|degli|dello|in|sul|sulla|e)\s|dell'|nell'|d')*(?!Tel\b|Fax\b)[A-Z][\w'-]*)*(?:\s\([A-Z]{2}\))?
street_address¶
Italian street address (indirizzo): Via, Viale, Piazza, Corso, Largo, Vicolo, Strada, Contrada or Località (also V.le, P.zza, C.so), capitalized or not, the name and number, like Via Giuseppe Garibaldi, 12/A.
rre.it.street_address(text)
\b(?i:(?:Via|Viale|Piazza|Piazzale|Corso|Largo|Vicolo|Strada|Contrada|Località)\s|(?:V\.le|P\.zza|P\.le|C\.so|C\.da|Loc\.)\s?)(?:(?:di|del|della|delle|dei|degli|dello)\s|dell'|d')*(?!(?i:whatsapp|telegram|facebook|instagram|messenger|skype|signal|sms|pec|(?:e-?)?mail|internet|web)\b)(?:\d{1,2}°?\s)?[A-Z][\w'. -]{0,40}?,?\s(?:n[.°]?\s?)?\d{1,4}(?:\s?/\s?[A-Za-z0-9]{1,3}|\s?bis|[A-Z])?\b
Vehicles, ships and parcels¶
| function | checksum validator |
|---|---|
rre.it.aircraft_registration |
|
rre.it.license_plate |
aircraft_registration¶
Italian aircraft registration (marche di immatricolazione): I- followed by four letters, like I-ABCD.
rre.it.aircraft_registration(text)
\bI-[A-Z]{4}\b
license_plate¶
Italian license plate (targa): two letters, three digits and two letters, without I, O, Q or U, like AB 123 CD, AB123CD or AB-123-CD.
rre.it.license_plate(text)
\b[A-HJ-NPR-TV-Z]{2}[ -]?\d{3}[ -]?[A-HJ-NPR-TV-Z]{2}\b
Justice and police¶
| function | checksum validator |
|---|---|
rre.it.ecli |
ecli¶
European Case Law Identifier (ECLI) of an Italian court decision: ECLI:IT:, the court, the year and the number, like ECLI:IT:CASS:2016:12345CIV.
rre.it.ecli(text)
\bECLI:IT:[A-Z]+:\d{4}:[A-Z0-9.]*[A-Z0-9]