TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/TI-Sin-Problemas/erpnext_mexico_compliance/llms.txt
Use this file to discover all available pages before exploring further.
controllers.validators module provides regex-based validators for Mexican government-issued identifiers. These functions are used internally by the app — for example, when saving a Customer (RFC) or an Employee (CURP) — and can be imported directly into any custom Frappe app that needs to validate these identifiers before stamping a CFDI or saving a record.
is_valid_rfc(rfc: str) → bool
Validates an RFC (Registro Federal de Contribuyentes), the Mexican federal taxpayer registration number issued by the SAT. ReturnsTrue if the RFC string matches the expected format, False otherwise.
RFC structure
An RFC encodes the taxpayer’s name initials and date of birth (or incorporation date for companies) followed by a three-character homologation key:| Segment | Length | Description |
|---|---|---|
| Name initials | 3–4 letters | 3 letters for legal entities; 4 letters for individuals |
| Birth / incorporation date | 6 digits | YYMMDD format |
| Homologation key | 3 characters | Alphanumeric (A-Z, 0-9) — assigned by the SAT |
- Legal entities (companies): 12-character RFC (
3 letters + 6 digits + 3 chars) - Natural persons (individuals): 13-character RFC (
4 letters + 6 digits + 3 chars)
Usage
Regex pattern
- Uppercase letters only (
A-Z,Ñ, and&for the ampersand used in some company names) - A valid month segment (
01–12) - A valid day segment (
01–31) — note this is a format check, not a calendar check - An alphanumeric homologation key
is_valid_curp(curp: str) → bool
Validates a CURP (Clave Única de Registro de Población), the 18-character personal identity code assigned by the Mexican government to every citizen and resident. ReturnsTrue if the CURP string matches the expected format, False otherwise.
CURP structure
| Segment | Length | Description |
|---|---|---|
| First letter of first surname | 1 letter | |
| First internal vowel of first surname | 1 vowel | |
| First letter of second surname | 1 letter | |
| First letter of given name | 1 letter | |
| Date of birth | 6 digits | YYMMDD format |
| Gender | 1 letter | H (hombre / male) or M (mujer / female) |
| State of birth | 2 letters | Two-letter SAT state code (e.g. DF, NL, JC) |
| Internal consonants | 3 consonants | First internal consonant of each surname and given name |
| Check digits | 2 characters | Homonymy differentiator (alphanumeric) + verification digit |
Usage
Regex pattern
The validator uses a verbose multi-line pattern compiled withre.VERBOSE:
re.VERBOSE, whitespace and line breaks inside the raw string are ignored during matching.
is_match(pattern, string, flags=0) → bool
The underlying helper used by bothis_valid_rfc and is_valid_curp. Compiles a regex pattern and returns True if the string fully matches it from start to end (re.match).
is_match directly in custom validators by passing any standard Python regex flags (e.g. re.IGNORECASE, re.VERBOSE).
These validators enforce format only — they verify that the string matches the structural rules defined by the SAT, but they do not check whether the RFC or CURP actually exists in any SAT registry. For RFC existence validation against the SAT, use the CFDI web service’s status endpoint.