
Why We Built an API for Spanish Fiscal ID Validation Instead of Just Implementing It
A few months ago I was integrating fiscal identifier validation into a project. I googled it, found a 30-line JavaScript function, copied it, tested it with four cases, and it worked. I dropped it into the codebase and forgot about it. Three months later, a user emailed us: their CIF wasn't validating. It was a perfectly valid CIF. That's when I understood there's a difference between implementing validation and maintaining it correctly . The problem isn't that it's hard Validating a NIF seems straightforward: 8 digits, one letter, modulo 23. Any developer can implement it in ten minutes. The problems appear when you scratch the surface: NIF: the basic algorithm works, but there are special formats — K, L and M NIFs for specific cases — that most implementations simply ignore. NIE: starts with X, Y or Z, then follows the NIF algorithm with substitution. Most regex you'll find online accept 7 or 8 digits interchangeably, when the correct format depends on the prefix. CIF: this is where
Continue reading on Dev.to Webdev
Opens in a new tab



