-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathvalidators.1
More file actions
2091 lines (2089 loc) · 48.8 KB
/
Copy pathvalidators.1
File metadata and controls
2091 lines (2089 loc) · 48.8 KB
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "VALIDATORS" "1" "May 01, 2025" "0.35.0" "validators"
.SH NAME
validators \- Python Data Validation for Humans™
.sp
\fI\%PyCQA\fP \fI\%SAST\fP \fI\%Docs\fP \fI\%Version\fP \fI\%Downloads\fP
.sp
Python has all kinds of data validation tools, but every one of them
seems to require defining a schema or form. I wanted to create a simple
validation library where validating a simple value does not require
defining a form or a schema.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
pip install validators
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Then,
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
>>> import validators
>>>
>>> validators.email(\(aqsomeone@example.com\(aq)
True
.ft P
.fi
.UNINDENT
.UNINDENT
.SH RESOURCES
.INDENT 0.0
.IP \(bu 2
\fI\%Documentation\fP
.IP \(bu 2
\fI\%Bugtracker\fP
.IP \(bu 2
\fI\%Security\fP
.IP \(bu 2
\fI\%Code\fP
.UNINDENT
.sp
.ce
----
.ce 0
.sp
.INDENT 0.0
.INDENT 3.5
\fBPython 3.9\fP \fI\%reaches EOL in\fP
\fBOctober 2025.\fP
.UNINDENT
.UNINDENT
.SS Install and Use
.SS Installation
.sp
Execute the following command:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
pip install validators
.ft P
.fi
.UNINDENT
.UNINDENT
.INDENT 0.0
.INDENT 3.5
It\(aqs preferable to use \fBpip\fP within a virtual environment.
.UNINDENT
.UNINDENT
.SS Usage
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
import validators
print(validators.email(\(aqsomeone@example.com\(aq))
.ft P
.fi
.UNINDENT
.UNINDENT
.SS To raise validation error
.INDENT 0.0
.IP 1. 3
Either set the environment variable \fBRAISE_VALIDATION_ERROR\fP to
\fBTrue\fP
.INDENT 3.0
.INDENT 3.5
.sp
.nf
.ft C
$ export RAISE_VALIDATION_ERROR=True
$ python \-c \(dqfrom validators import url; print(url(\(aqhttps//bad_url\(aq))\(dq
Traceback (most recent call last):
File \(dq<string>\(dq, line 1, in <module>
File \(dq/path/to/lib/validators/utils.py\(dq, line 87, in wrapper
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
validators.utils.ValidationError: ValidationError(func=url, args={\(aqvalue\(aq: \(aqhttps//bad_url\(aq})
.ft P
.fi
.UNINDENT
.UNINDENT
.IP 2. 3
Or pass \fBr_ve=True\fP to each caller function:
.INDENT 3.0
.INDENT 3.5
.sp
.nf
.ft C
$ python \-c \(dqfrom validators.card import visa; print(visa(\(aqbad_visa_number\(aq, r_ve=True))\(dq
Traceback (most recent call last):
File \(dq<string>\(dq, line 1, in <module>
File \(dq/path/to/lib/validators/utils.py\(dq, line 87, in wrapper
raise ValidationError(func, _func_args_as_dict(func, *args, **kwargs))
validators.utils.ValidationError: ValidationError(func=visa, args={\(aqvalue\(aq: \(aqbad_visa_number\(aq})
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.SS between
.INDENT 0.0
.TP
.B validators.between.between(value: PossibleValueTypes, /, *, min_val: PossibleValueTypes | AbsMin | None = None, max_val: PossibleValueTypes | AbsMax | None = None)
Validate that a number is between minimum and/or maximum value.
.sp
This will work with any comparable type, such as floats, decimals and dates
not just integers. This validator is originally based on [WTForms\-NumberRange\-Validator][1].
.sp
[1]: \fI\%https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L166\-L220\fP
.sp
Examples
.sp
.nf
.ft C
>>> from datetime import datetime
>>> between(5, min_val=2)
True
>>> between(13.2, min_val=13, max_val=14)
True
>>> between(500, max_val=400)
ValidationError(func=between, args={\(aqvalue\(aq: 500, \(aqmax_val\(aq: 400})
>>> between(
\&... datetime(2000, 11, 11),
\&... min_val=datetime(1999, 11, 11)
\&... )
True
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBvalue\fP \-\- Value which is to be compared.
.IP \(bu 2
\fBmin_val\fP \-\- The minimum required value of the number.
If not provided, minimum value will not be checked.
.IP \(bu 2
\fBmax_val\fP \-\- The maximum value of the number.
If not provided, maximum value will not be checked.
.UNINDENT
.TP
.B Returns
If \fIvalue\fP is in between the given conditions.
(ValidationError): If \fIvalue\fP is not in between the given conditions.
.TP
.B Return type
(Literal[True])
.TP
.B Raises
.INDENT 7.0
.IP \(bu 2
\fB(\fP\fBValueError\fP\fB)\fP \-\- If \fImin_val\fP is greater than \fImax_val\fP\&.
.IP \(bu 2
\fB(\fP\fBTypeError\fP\fB)\fP \-\- If there\(aqs a type mismatch during comparison.
.UNINDENT
.UNINDENT
.sp
\fBNOTE:\fP
.INDENT 7.0
.INDENT 3.5
.INDENT 0.0
.IP \(bu 2
\fIPossibleValueTypes\fP = \fITypeVar(\(dqPossibleValueTypes\(dq, int, float, str, datetime)\fP
.IP \(bu 2
If neither \fImin_val\fP nor \fImax_val\fP is provided, result will always be \fITrue\fP\&.
.UNINDENT
.UNINDENT
.UNINDENT
.UNINDENT
.SS card
.INDENT 0.0
.TP
.B validators.card.amex(value: str, /)
Return whether or not given value is a valid American Express card number.
.sp
Examples
.sp
.nf
.ft C
>>> amex(\(aq378282246310005\(aq)
True
>>> amex(\(aq4242424242424242\(aq)
ValidationError(func=amex, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- American Express card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid American Express card number.
(ValidationError): If \fIvalue\fP is an invalid American Express card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.card_number(value: str, /)
Return whether or not given value is a valid generic card number.
.sp
This validator is based on [Luhn\(aqs algorithm][1].
.sp
[1]: \fI\%https://github.com/mmcloughlin/luhn\fP
.sp
Examples
.sp
.nf
.ft C
>>> card_number(\(aq4242424242424242\(aq)
True
>>> card_number(\(aq4242424242424241\(aq)
ValidationError(func=card_number, args={\(aqvalue\(aq: \(aq4242424242424241\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Generic card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid generic card number.
(ValidationError): If \fIvalue\fP is an invalid generic card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.diners(value: str, /)
Return whether or not given value is a valid Diners Club card number.
.sp
Examples
.sp
.nf
.ft C
>>> diners(\(aq3056930009020004\(aq)
True
>>> diners(\(aq4242424242424242\(aq)
ValidationError(func=diners, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Diners Club card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid Diners Club card number.
(ValidationError): If \fIvalue\fP is an invalid Diners Club card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.discover(value: str, /)
Return whether or not given value is a valid Discover card number.
.sp
Examples
.sp
.nf
.ft C
>>> discover(\(aq6011111111111117\(aq)
True
>>> discover(\(aq4242424242424242\(aq)
ValidationError(func=discover, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Discover card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid Discover card number.
(ValidationError): If \fIvalue\fP is an invalid Discover card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.jcb(value: str, /)
Return whether or not given value is a valid JCB card number.
.sp
Examples
.sp
.nf
.ft C
>>> jcb(\(aq3566002020360505\(aq)
True
>>> jcb(\(aq4242424242424242\(aq)
ValidationError(func=jcb, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- JCB card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid JCB card number.
(ValidationError): If \fIvalue\fP is an invalid JCB card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.mastercard(value: str, /)
Return whether or not given value is a valid Mastercard card number.
.sp
Examples
.sp
.nf
.ft C
>>> mastercard(\(aq5555555555554444\(aq)
True
>>> mastercard(\(aq4242424242424242\(aq)
ValidationError(func=mastercard, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Mastercard card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid Mastercard card number.
(ValidationError): If \fIvalue\fP is an invalid Mastercard card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.mir(value: str, /)
Return whether or not given value is a valid Mir card number.
.sp
Examples
.sp
.nf
.ft C
>>> mir(\(aq2200123456789019\(aq)
True
>>> mir(\(aq4242424242424242\(aq)
ValidationError(func=mir, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Mir card number string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid Mir card number.
(ValidationError): If \fIvalue\fP is an invalid Mir card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.unionpay(value: str, /)
Return whether or not given value is a valid UnionPay card number.
.sp
Examples
.sp
.nf
.ft C
>>> unionpay(\(aq6200000000000005\(aq)
True
>>> unionpay(\(aq4242424242424242\(aq)
ValidationError(func=unionpay, args={\(aqvalue\(aq: \(aq4242424242424242\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- UnionPay card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid UnionPay card number.
(ValidationError): If \fIvalue\fP is an invalid UnionPay card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.card.visa(value: str, /)
Return whether or not given value is a valid Visa card number.
.sp
Examples
.sp
.nf
.ft C
>>> visa(\(aq4242424242424242\(aq)
True
>>> visa(\(aq2223003122003222\(aq)
ValidationError(func=visa, args={\(aqvalue\(aq: \(aq2223003122003222\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Visa card number string to validate
.TP
.B Returns
If \fIvalue\fP is a valid Visa card number.
(ValidationError): If \fIvalue\fP is an invalid Visa card number.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS country
.INDENT 0.0
.TP
.B validators.country.calling_code(value: str, /)
Validates given calling code.
.sp
This performs country\(aqs calling code validation.
.sp
Examples
.sp
.nf
.ft C
>>> calling_code(\(aq+91\(aq)
True
>>> calling_code(\(aq\-31\(aq)
ValidationError(func=calling_code, args={\(aqvalue\(aq: \(aq\-31\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Country\(aqs calling code string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid calling code.
(ValidationError): If \fIvalue\fP is an invalid calling code.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.country.country_code(value: str, /, *, iso_format: str = \(aqauto\(aq, ignore_case: bool = False)
Validates given country code.
.sp
This performs a case\-sensitive [ISO 3166][1] country code validation.
.sp
[1]: \fI\%https://www.iso.org/iso\-3166\-country\-codes.html\fP
.sp
Examples
.sp
.nf
.ft C
>>> country_code(\(aqGB\(aq, iso_format=\(aqalpha3\(aq)
ValidationError(func=country_code, args={\(aqvalue\(aq: \(aqGB\(aq, \(aqiso_format\(aq: \(aqalpha3\(aq})
>>> country_code(\(aqUSA\(aq)
True
>>> country_code(\(aq840\(aq, iso_format=\(aqnumeric\(aq)
True
>>> country_code(\(aqiN\(aq, iso_format=\(aqalpha2\(aq)
ValidationError(func=country_code, args={\(aqvalue\(aq: \(aqiN\(aq, \(aqiso_format\(aq: \(aqalpha2\(aq})
>>> country_code(\(aqZWE\(aq, iso_format=\(aqalpha3\(aq)
True
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBvalue\fP \-\- Country code string to validate.
.IP \(bu 2
\fBiso_format\fP \-\- ISO format to be used. Available options are:
\fIauto\fP, \fIalpha2\fP, \fIalpha3\fP and \fInumeric\fP\&.
.IP \(bu 2
\fBignore_case\fP \-\- Enable/Disable case\-sensitive matching.
.UNINDENT
.TP
.B Returns
If \fIvalue\fP is a valid country code.
(ValidationError): If \fIvalue\fP is an invalid country code.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.country.currency(value: str, /, *, skip_symbols: bool = True, ignore_case: bool = False)
Validates given currency code.
.sp
This performs [ISO 4217][1] currency code/symbol validation.
.sp
[1]: \fI\%https://www.iso.org/iso\-4217\-currency\-codes.html\fP
.sp
Examples
.sp
.nf
.ft C
>>> currency(\(aqUSD\(aq)
True
>>> currency(\(aqZWX\(aq)
ValidationError(func=currency, args={\(aqvalue\(aq: \(aqZWX\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBvalue\fP \-\- Currency code/symbol string to validate.
.IP \(bu 2
\fBskip_symbols\fP \-\- Skip currency symbol validation.
.IP \(bu 2
\fBignore_case\fP \-\- Enable/Disable case\-sensitive matching.
.UNINDENT
.TP
.B Returns
If \fIvalue\fP is a valid currency code.
(ValidationError): If \fIvalue\fP is an invalid currency code.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS cron
.INDENT 0.0
.TP
.B validators.cron.cron(value: str, /)
Return whether or not given value is a valid cron string.
.sp
Examples
.sp
.nf
.ft C
>>> cron(\(aq*/5 * * * *\(aq)
True
>>> cron(\(aq30\-20 * * * *\(aq)
ValidationError(func=cron, args={\(aqvalue\(aq: \(aq30\-20 * * * *\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Cron string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid cron string.
(ValidationError): If \fIvalue\fP is an invalid cron string.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS crypto_addresses
.INDENT 0.0
.TP
.B validators.crypto_addresses.bsc_address(value: str, /)
Return whether or not given value is a valid binance smart chain address.
.sp
Full validation is implemented for BSC addresses.
.sp
Examples
.sp
.nf
.ft C
>>> bsc_address(\(aq0x4e5acf9684652BEa56F2f01b7101a225Ee33d23f\(aq)
True
>>> bsc_address(\(aq0x4g5acf9684652BEa56F2f01b7101a225Eh33d23z\(aq)
ValidationError(func=bsc_address, args={\(aqvalue\(aq: \(aq0x4g5acf9684652BEa56F2f01b7101a225Eh33d23z\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- BSC address string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid bsc address.
(ValidationError): If \fIvalue\fP is an invalid bsc address.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.crypto_addresses.btc_address(value: str, /)
Return whether or not given value is a valid bitcoin address.
.sp
Full validation is implemented for P2PKH and P2SH addresses.
For segwit addresses a regexp is used to provide a reasonable
estimate on whether the address is valid.
.sp
Examples
.sp
.nf
.ft C
>>> btc_address(\(aq3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69\(aq)
True
>>> btc_address(\(aq1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2\(aq)
ValidationError(func=btc_address, args={\(aqvalue\(aq: \(aq1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Bitcoin address string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid bitcoin address.
(ValidationError): If \fIvalue\fP is an invalid bitcoin address.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.crypto_addresses.eth_address(value: str, /)
Return whether or not given value is a valid ethereum address.
.sp
Full validation is implemented for ERC20 addresses.
.sp
Examples
.sp
.nf
.ft C
>>> eth_address(\(aq0x9cc14ba4f9f68ca159ea4ebf2c292a808aaeb598\(aq)
True
>>> eth_address(\(aq0x8Ba1f109551bD432803012645Ac136ddd64DBa72\(aq)
ValidationError(func=eth_address, args={\(aqvalue\(aq: \(aq0x8Ba1f109551bD432803012645Ac136ddd64DBa72\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Ethereum address string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid ethereum address.
(ValidationError): If \fIvalue\fP is an invalid ethereum address.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.crypto_addresses.trx_address(value: str, /)
Return whether or not given value is a valid tron address.
.sp
Full validation is implemented for TRC20 tron addresses.
.sp
Examples
.sp
.nf
.ft C
>>> trx_address(\(aqTLjfbTbpZYDQ4EoA4N5CLNgGjfbF8ZWz38\(aq)
True
>>> trx_address(\(aqTR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd\(aq)
ValidationError(func=trx_address, args={\(aqvalue\(aq: \(aqTR2G7Rm4vFqF8EpY4U5xdLdQ7XgJ2U8Vd\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- Tron address string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid tron address.
(ValidationError): If \fIvalue\fP is an invalid tron address.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS domain
.INDENT 0.0
.TP
.B validators.domain.domain(value: str, /, *, consider_tld: bool = False, rfc_1034: bool = False, rfc_2782: bool = False)
Return whether or not given value is a valid domain.
.sp
Examples
.sp
.nf
.ft C
>>> domain(\(aqexample.com\(aq)
True
>>> domain(\(aqexample.com/\(aq)
ValidationError(func=domain, args={\(aqvalue\(aq: \(aqexample.com/\(aq})
>>> # Supports IDN domains as well::
>>> domain(\(aqxn\-\-\-\-gtbspbbmkef.xn\-\-p1ai\(aq)
True
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBvalue\fP \-\- Domain string to validate.
.IP \(bu 2
\fBconsider_tld\fP \-\- Restrict domain to TLDs allowed by IANA.
.IP \(bu 2
\fBrfc_1034\fP \-\- Allows optional trailing dot in the domain name.
Ref: [RFC 1034](\fI\%https://www.rfc\-editor.org/rfc/rfc1034\fP).
.IP \(bu 2
\fBrfc_2782\fP \-\- Domain name is of type service record.
Allows optional underscores in the domain name.
Ref: [RFC 2782](\fI\%https://www.rfc\-editor.org/rfc/rfc2782\fP).
.UNINDENT
.TP
.B Returns
If \fIvalue\fP is a valid domain name.
(ValidationError): If \fIvalue\fP is an invalid domain name.
.TP
.B Return type
(Literal[True])
.TP
.B Raises
\fB(\fP\fBUnicodeError\fP\fB)\fP \-\- If \fIvalue\fP cannot be encoded into \fIidna\fP or decoded into \fIutf\-8\fP\&.
.UNINDENT
.UNINDENT
.SS email
.INDENT 0.0
.TP
.B validators.email.email(value: str, /, *, ipv6_address: bool = False, ipv4_address: bool = False, simple_host: bool = False, rfc_1034: bool = False, rfc_2782: bool = False)
Validate an email address.
.sp
This was inspired from [Django\(aqs email validator][1].
Also ref: [RFC 1034][2], [RFC 5321][3] and [RFC 5322][4].
.sp
[1]: \fI\%https://github.com/django/django/blob/main/django/core/validators.py#L174\fP
[2]: \fI\%https://www.rfc\-editor.org/rfc/rfc1034\fP
[3]: \fI\%https://www.rfc\-editor.org/rfc/rfc5321\fP
[4]: \fI\%https://www.rfc\-editor.org/rfc/rfc5322\fP
.sp
Examples
.sp
.nf
.ft C
>>> email(\(aqsomeone@example.com\(aq)
True
>>> email(\(aqbogus@@\(aq)
ValidationError(func=email, args={\(aqvalue\(aq: \(aqbogus@@\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBvalue\fP \-\- eMail string to validate.
.IP \(bu 2
\fBipv6_address\fP \-\- When the domain part is an IPv6 address.
.IP \(bu 2
\fBipv4_address\fP \-\- When the domain part is an IPv4 address.
.IP \(bu 2
\fBsimple_host\fP \-\- When the domain part is a simple hostname.
.IP \(bu 2
\fBrfc_1034\fP \-\- Allow trailing dot in domain name.
Ref: [RFC 1034](\fI\%https://www.rfc\-editor.org/rfc/rfc1034\fP).
.IP \(bu 2
\fBrfc_2782\fP \-\- Domain name is of type service record.
Ref: [RFC 2782](\fI\%https://www.rfc\-editor.org/rfc/rfc2782\fP).
.UNINDENT
.TP
.B Returns
If \fIvalue\fP is a valid eMail.
(ValidationError): If \fIvalue\fP is an invalid eMail.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS encoding
.INDENT 0.0
.TP
.B validators.encoding.base16(value: str, /)
Return whether or not given value is a valid base16 encoding.
.sp
Examples
.sp
.nf
.ft C
>>> base16(\(aqa3f4b2\(aq)
True
>>> base16(\(aqa3f4Z1\(aq)
ValidationError(func=base16, args={\(aqvalue\(aq: \(aqa3f4Z1\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- base16 string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid base16 encoding.
(ValidationError): If \fIvalue\fP is an invalid base16 encoding.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.encoding.base32(value: str, /)
Return whether or not given value is a valid base32 encoding.
.sp
Examples
.sp
.nf
.ft C
>>> base32(\(aqMFZWIZLTOQ======\(aq)
True
>>> base32(\(aqMfZW3zLT9Q======\(aq)
ValidationError(func=base32, args={\(aqvalue\(aq: \(aqMfZW3zLT9Q======\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- base32 string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid base32 encoding.
(ValidationError): If \fIvalue\fP is an invalid base32 encoding.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.encoding.base58(value: str, /)
Return whether or not given value is a valid base58 encoding.
.sp
Examples
.sp
.nf
.ft C
>>> base58(\(aq14pq6y9H2DLGahPsM4s7ugsNSD2uxpHsJx\(aq)
True
>>> base58(\(aqcUSECm5YzcXJwP\(aq)
True
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- base58 string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid base58 encoding.
(ValidationError): If \fIvalue\fP is an invalid base58 encoding.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B validators.encoding.base64(value: str, /)
Return whether or not given value is a valid base64 encoding.
.sp
Examples
.sp
.nf
.ft C
>>> base64(\(aqY2hhcmFjdGVyIHNldA==\(aq)
True
>>> base64(\(aqcUSECm5YzcXJwP\(aq)
ValidationError(func=base64, args={\(aqvalue\(aq: \(aqcUSECm5YzcXJwP\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- base64 string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid base64 encoding.
(ValidationError): If \fIvalue\fP is an invalid base64 encoding.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.SS finance
.INDENT 0.0
.TP
.B validators.finance.cusip(value: str)
Return whether or not given value is a valid CUSIP.
.sp
Checks if the value is a valid [CUSIP][1].
[1]: \fI\%https://en.wikipedia.org/wiki/CUSIP\fP
.sp
Examples
.sp
.nf
.ft C
>>> cusip(\(aq037833DP2\(aq)
True
>>> cusip(\(aq037833DP3\(aq)
ValidationError(func=cusip, args={\(aqvalue\(aq: \(aq037833DP3\(aq})
.ft P
.fi
.INDENT 7.0
.TP
.B Parameters
\fBvalue\fP \-\- CUSIP string to validate.
.TP
.B Returns
If \fIvalue\fP is a valid CUSIP string.
(ValidationError): If \fIvalue\fP is an invalid CUSIP string.
.TP
.B Return type
(Literal[True])
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP