Menu

Validating Mexican RFC and CURP in Python: check digits, edge cases, and when you need a live lookup
📰

Validating Mexican RFC and CURP in Python: check digits, edge cases, and when you need a live lookup

DEV Community·Adrian Rangel·about 8 hours ago
#BzDj2XLE
#dev#curp#return#digit#mexcheck
Reading 0:00
15s threshold

Disclosure: I'm Adrian Rangel, the founder of MexCheck, which I mention near the end. The first two thirds of this post are plain Python with no dependencies, and you can use them without signing up for anything. All identifiers below are public examples, not real people.

If your company onboards Mexican customers, contractors or suppliers, sooner or later a form asks for an RFC (the SAT tax ID) or a CURP (the national population ID). Payroll needs both, CFDI invoicing needs the RFC, and KYC usually wants the CURP.

A regex copied from somewhere catches some typos, but lets through wrong check digits, impossible dates, and IDs that are well formed but belong to nobody.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.