1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
test_mx_rfc.doctest - more detailed doctests for the stdnum.mx.rfc module
Copyright (C) 2015 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
This file contains more detailed doctests for the stdnum.mx.rfc module.
>>> from stdnum.mx import rfc
>>> from stdnum.exceptions import *
The six digits are supposed to form a valid date.
>>> rfc.validate('ABCD 123456')
Traceback (most recent call last):
...
InvalidComponent: ...
The last three digits are in a special alphabet and should only contain
1-9A-V, 1-9A-Z and 0-9A for the last digits.
>>> rfc.validate('AABN 821103 8\xd12') # \xd1 is the N with tilde
Traceback (most recent call last):
...
InvalidFormat: ...
The first four digits should only be letters for 10 or 13-digit numbers.
>>> rfc.validate('ABCD 12345678')
Traceback (most recent call last):
...
InvalidFormat: ...
The first four digits of a personal number should not be one of the
blacklisted words.
>>> rfc.validate('CACA 580710 NF7')
Traceback (most recent call last):
...
InvalidComponent: ...
Only personal numbers are allowed to be missing the "homoclave" (check
digits) part.
>>> rfc.validate('AKJ970902')
Traceback (most recent call last):
...
InvalidLength: ...
A large number of numbers that are in use appear to have invalid check
digits. This has been found in about 1.5% of all numbers found. For this
reason, by default, validation of check digits has been disabled and can be
enabled explicitly.
>>> rfc.validate('SIN 931116 9P8')
'SIN9311169P8'
>>> rfc.validate('SIN 931116 9P8', validate_check_digits=True)
Traceback (most recent call last):
...
InvalidChecksum: ...
>>> rfc.validate('CCM 650122 I06')
'CCM650122I06'
>>> rfc.validate('CCM 650122 I06', validate_check_digits=True)
Traceback (most recent call last):
...
InvalidComponent: ...
Some extra formatting checks:
>>> rfc.format('VSM140430NQA')
'VSM 140430 NQA'
>>> rfc.format('ZUT A770215LK0')
'ZUTA 770215 LK0'
These have been found online and should all be valid numbers. Note that these
numbers all have valid check digits (also see the list below).
>>> numbers = '''
...
... &&&030828PX7
... &JE040614N51
... AA&0607148I0
... AAA390128530
... AAAA791128D63
... AAAL730401TE0
... AACA700913KZ0
... AACC421231BH1
... AADS251231CG0
... AALC680929LH8
... AAM090224BC2
... AARR621113SN7
... ABA130601BD3
... ABH0507252D9
... ACA120116TX5
... ACO071219F51
... AEAJ390701E82
... AEL7407151YA
... AEM100930B11
... AHO120203E8A
... ALD950921G27
... ALE8401268K8
... AMA990219PF8
... AME040430UM8
... AME110909530
... AMM020222UT3
... ANI0112176N8
... AON0210014T5
... AOX040831A59
... AP&0305026J9
... APA371201PQ7
... AQU920317P4A
... ARO020221DQ4
... ASE9112306M9
... ATB081212MN5
... AUD000704II1
... AUHF891016KE4
... AWI1206064H1
... AYP110530D73
... B&D9605298Y3
... BADY7101185W6
... BEE070927MH0
... BER090921FJ6
... BIHC5111253I7
... BLN130425JU7
... BMI880419PR5
... BNE110914EY0
... BSP0603203U3
... BUGA701115I43
... CAR910506BW8
... CBC900829152
... CCS8512024CA
... CDE110928FR0
... CEG970917HY3
... CEI111208UJ8
... CET790711B43
... CEX910718C75
... CFE010608HC8
... CGB000229SW0
... CIG120628NQ1
... CIN831107B41
... CIT900525168
... CLO070618EY6
... CLO110607257
... CLO850611371
... CMA7708263Y7
... CMA970306DZ8
... CME990423373
... CMI0507204U8
... CMO101104D21
... CNR100325T71
... COI090127UY5
... COML8103203QA
... COP891005HV6
... CPR0611212K8
... CSB021029689
... CSI050527PE4
... CSI900816E23
... CSM130516IT5
... CSU000912EH0
... CTE870318ANA
... CTR0501281A7
... CTS840406DB5
... CTV080213S16
... CUAF680927LM6
... CVI961129D88
... DAM121219GU4
... DCA050617BJ7
... DCF080331IP7
... DCP1008179J4
... DHO100211PP9
... DIN130417NB8
... DIP0405273R5
... DIR070208V76
... DIS9611059T1
... DIV050625LE1
... DMM120201G43
... DMS121114BV6
... DPU070904692
... DVS120703FD1
... ECM080228KF1
... EDI000229CA3
... EEM9110114W4
... EGA060426LW6
... EIA870112MW6
... EIE080701SL6
... EIM861215GH7
... EIP971118EE0
... EITM9103155L7
... EMA001219M72
... EME950412SS8
... ENI731210FS2
... ENP100804LU4
... EPL031009LA3
... EPM990712PX9
... EPR920313DS8
... ESI920217GY0
... EUDC730505US6
... EYA810212AB7
... EYO121214DD5
... FAM000229SB8
... FCM0512093V7
... FCR930924UP5
... FDI060505DD8
... FERL530506LL2
... FLO9205187K8
... FME780808PH2
... FMP110620626
... FPC960606SS7
... FQU040210VB6
... GABA930110DY7
... GAD8509039E9
... GAF091006GL7
... GAGS8602119P9
... GAI670926SX4
... GBE910314CY9
... GBM110523N11
... GCT0205243T8
... GEC091113R94
... GEN060113JT9
... GGS1306077E2
... GIAI6703203N6
... GIN130711BX1
... GIN9806308G0
... GLA1001272R3
... GMA050607UA0
... GMI920724CP5
... GMO030628DI0
... GMX0912018E6
... GOAJ7101257MA
... GOBM630601RQ6
... GOVB6202103B1
... GTL101217DPA
... GUI990521N70
... GURK651124IZ6
... GYA010601HZ2
... HAKC800506G89
... HEA080829QE4
... HEM881018M63
... HIAD7004306I3
... HIM950519AS3
... HST051115KD6
... HUM131108DJ7
... IAG960627I24
... ICR131219UR2
... ICV111124GA3
... ICW020809NG4
... IEO861107K41
... IET040122JP4
... IET1402203U2
... IJC090327V63
... ILM130517SJ6
... IME060217HN7
... IPA090810Q33
... ISD9609109M3
... ITE040705LM7
... ITM040310AX8
... ITM7002044W3
... ITM891121LZ9
... ITO090804L92
... IUS9207088R5
... JET0811207A7
... JINA4912084Z8
... JJO021128CS9
... JOFF550129TD7
... KCO990630SQ4
... KUC120227CP8
... LBN120207CE8
... LEAJ570610M32
... LED070424K80
... LIVR600908A58
... LMX120112CH1
... LRE050221F14
... LTR101108SK5
... LTS000117Q95
... LUT0504217B1
... MAC0501069H5
... MAC050302QU4
... MAE100225TF0
... MALR850723RK4
... MAOA800509SH5
... MAPA600915DB4
... MAR960628QU0
... MAV890913NY0
... MBU060512RE7
... MCA851223JI9
... MCP100710IH6
... MCS830224156
... MDM011001DD7
... MECJ730513KC7
... MELF7605095R6
... MIR9812154E0
... MIT110829255
... MKE040510HW9
... MLM020809894
... MME120612IJ5
... MME820427S6A
... MME9710313Z4
... MOCC891114BA9
... MOD9904275G7
... MRG900406M6A
... MSI041208CR0
... MSU121003LR3
... MTR091125TJ8
... MUÑ110218LJ6
... MXS030318BP0
... NAJ120705J5A
... NARF561006LT9
... NFI000511G42
... NIC120302LE4
... NOCJ750806BJA
... OHA0204186H2
... OIL080603P74
... OIN970513LM7
... OOM060208MC5
... ORO040505KH3
... ORS0011148U8
... OVS041008711
... PAP041025A11
... PBC910219RI2
... PCS091030DZA
... PDI630218N32
... PEL910625UQ4
... PGT110128I84
... PII040123JR9
... PIN8709103A4
... PIT1207186S3
... PLA020617B95
... PME8308184S4
... PMI0110161Q4
... PPM970110676
... PPT991115IR3
... PRA071201A18
... PRA850314FE5
... PRO060904RR8
... QVI850529SP8
... RABT551122827
... RAO821016K97
... RCV060828NE3
... RDI841003QJ4
... REG070627EF9
... REI120227C54
... RIGL6608198W7
... RME960329V67
... ROZS700918HL9
... RRE010202L83
... RUAA751115C42
... RUAJ8104018GA
... RZS9003238P5
... SAGE661012E96
... SALM760305JP4
... SAVA810110EN5
... SBR811009760
... SCE000520HU0
... SCI090109TZ2
... SCO050124QL2
... SDA8902091QA
... SEP051121DU8
... SES0601271U0
... SGY100210UL2
... SIA0803073Z2
... SIM080104CM6
... SIN9904064B4
... SME011012Q43
... SME020208GXA
... SME060406U67
... SME111212CA4
... SOP0410217V5
... SOP940502FF5
... SOR9403107MA
... SOTG740115G1A
... SPL910701FD9
... STP110106D88
... TCS0104276P5
... TEC0306066L6
... TEE060928R87
... TME930929DE1
... TQI090928UR4
... TSP931104UI0
... UAI010212HW5
... UEE110902V5A
... UFA1010116X3
... VBF951020KT3
... VCA0903116M7
... VCO960628NZ0
... VEFC6503094Q6
... VEO100223D10
... VMI820313C9A
... VMU930407NFA
... VSM040108TS6
... VSO090204AF1
... XCO111215IM0
... YAT000229588
... ZEJ060728K11
... ZENP8101128Y0
... ZGU920526T43
... ZZE040708QJ9
...
... '''
>>> [x for x in numbers.splitlines() if x and not rfc.is_valid(x, validate_check_digits=True)]
[]
The following numbers were also found online, and while they appear to be in
use and referencing existing persons or organisations, the check digit does
not validate. All of these have been checked to be valid on
https://portalsat.plataforma.sat.gob.mx/ConsultaRFC/
(note that this website expects ISO-8859-1 encoded numbers)
>>> numbers = '''
...
... AAC0903183F6
... AAMM450222AJ1
... ALC920108P18
... AMC020204AB7
... AOM920820BEA
... ASA971202EB5
... ASE0804046M8
... AÑE9902224Z4
... BABC300126Q66
... BAÑ930616R66
... BER060923LW4
... BFI981221MG0
... BLM890223FH1
... BOJR890112DB9
... BOR071120HE7
... CAMG590407QSA
... CAMR620930HG5
... CAVB360920196
... CCB080911PV3
... CCL020604CX0
... CDO070410V77
... CLA091217733
... CLM9407017W4
... CME030507A29
... CME9809141L6
... CME990816951
... CMS071226LN2
... COCA8007229UA
... CPC080624C48
... CTA071106464
... CUP820427ID9
... DBE051005PT3
... DEKR6305193Q2
... DES8707223AA
... DJT031205MG4
... DRA950811S25
... EDG000413BF2
... EME1006143T6
... EQU810430193
... FAE8509042W7
... FIS0008226ZA
... FME9305279N0
... FSA080813655
... FSI900505I74
... GIR940318DF0
... GJO891005N53
... GMA080728MJ0
... GME9606038V6
... GOC841221BK0
... GWS860313JA3
... HHO900507844
... HME020215QTA
... ICO990503PG4
... IDE930601FJ4
... IME0610197B2
... ISM0403025G3
... KAK030512QD7
... KMN041126K5A
... KZY041011E20
... LME9405237U7
... LMI0811119C5
... LOCB6410225K0
... LOMM8110052J4
... MALC721019EV6
... MDI931014D37
... MFA840320DX0
... MGR070820G78
... MPT000824LH7
... MSA850111TE1
... NIÑ7409256U1
... NSN000704SY3
... NYL850506BJ8
... OIC060523UW1
... OMD100907CJ4
... OPP010927SA5
... OTM090818KS6
... PEJE480914ES9
... PERL640914HY9
... PPA100118E37
... PTS091204M83
... ROCS550714PC0
... SIG060311PN2
... SIT060329RA7
... SME100414QY9
... SME9502015F6
... SMP060331P74
... SMR011108KB9
... SOMF730101689
... SSB9512118M1
... STM000215AG9
... TFS011012M18
... TLO020509RK3
... TME940420LV5
... TORE4007065V7
... TPM06111759A
... TPT0202135S1
... TPT890516JP5
... VAME720111AA4
... WME000218GK3
... YME9610251W6
...
... '''
>>> [x for x in numbers.splitlines() if x and not rfc.is_valid(x)]
[]
|