最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regex for Italian fiscal code, with uppercase letters - Stack Overflow

programmeradmin3浏览0评论

I have this regular expression for the Italian fiscal code which works.

^([A-Za-z]{6}[0-9lmnpqrstuvLMNPQRSTUV]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9lmnpqrstuvLMNPQRSTUV]{2}[A-Za-z]{1}[0-9lmnpqrstuvLMNPQRSTUV]{3}[A-Za-z]{1})$|([0-9]{11})$

I've tried this one.

^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1})$|([0-9]{11})$

It works as I want,here but it is case insensitive in Google App Maker and also matching lowercase letters while I want to match only uppercase letters.

I have this regular expression for the Italian fiscal code which works.

^([A-Za-z]{6}[0-9lmnpqrstuvLMNPQRSTUV]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9lmnpqrstuvLMNPQRSTUV]{2}[A-Za-z]{1}[0-9lmnpqrstuvLMNPQRSTUV]{3}[A-Za-z]{1})$|([0-9]{11})$

I've tried this one.

^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1})$|([0-9]{11})$

It works as I want,here but it is case insensitive in Google App Maker and also matching lowercase letters while I want to match only uppercase letters.

Share Improve this question edited Oct 24, 2019 at 19:27 TechNerdXp asked Oct 24, 2019 at 3:28 TechNerdXpTechNerdXp 4173 gold badges8 silver badges26 bronze badges 12
  • What is your question? – Tim Biegeleisen Commented Oct 24, 2019 at 3:38
  • I want a regular expression for Italian fiscal code with letter uppercase only.. – TechNerdXp Commented Oct 24, 2019 at 3:40
  • Then remove the lowercase letters from the regex pattern. – Tim Biegeleisen Commented Oct 24, 2019 at 3:43
  • I tried it, It stops to work, I'm using in google app-maker environment. – TechNerdXp Commented Oct 24, 2019 at 3:45
  • 1 Can you show us some sample fiscal codes? – Tim Biegeleisen Commented Oct 24, 2019 at 3:45
 |  Show 7 more ments

2 Answers 2

Reset to default 11

While the accepted answer may be ok for a quick check it's still far from plete and it will let through some incorrect codes.

This blog post (in italian) describes what can be done with regular expression validation and how. I am not the author of the blog post, so all credits should go to him.

Long story short the result is:

/^(?:[A-Z][AEIOU][AEIOUX]|[AEIOU]X{2}|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}(?:[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[15MR][\dLMNP-V]|[26NS][0-8LMNP-U])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM]|[AC-EHLMPR-T][26NS][9V])|(?:[02468LNQSU][048LQU]|[13579MPRTV][26NS])B[26NS][9V])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[1-9MNP-V][\dLMNP-V]|[0L][1-9MNP-V]))[A-Z]$/i

This takes into account almost all rules, probably all rules that can be checked with a regular expression.

To create a full validation a code function will be required: the last 5 charachters of the fiscal codes are posed by a birthplace ID (4 char) and a CRC (1 char). Checking for the existence of the birthplace ID and applying the CRC calculation will plete the process.

Note: I haven't pletely verified all possible cases of fiscal codes but the regular expression has solved all validation problems I had. Also remember that even if you create a perfect validation function it still can be a fake, but formally correct, fiscal code.

This solves my problem...

^([A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST]{1}[0-9LMNPQRSTUV]{2}[A-Z]{1}[0-9LMNPQRSTUV]{3}[A-Z]{1})$|([0-9]{11})$

demo here.

there was some temporary problem in App Maker environment or just some confusion.

发布评论

评论列表(0)

  1. 暂无评论