|
1 | | -"""Inn.""" |
| 1 | +"""Russia INN.""" |
2 | 2 | |
3 | | -from src.validators.utils import validator |
| 3 | +from validators.utils import validator |
4 | 4 | |
5 | 5 | |
6 | 6 | @validator |
7 | | -def ru_inn(value: str, /): |
8 | | -"""Return whether or not given value is a valid russian individual tax number. |
| 7 | +def ru_inn(value: str): |
| 8 | +"""Validate a Russian INN (Taxpayer Identification Number). |
9 | 9 | |
10 | | - This validator is algorithm [1]. |
11 | | - |
12 | | - [1]: https://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика |
| 10 | + The INN can be either 10 digits (for companies) or 12 digits (for individuals). |
| 11 | + The function checks both the length and the control digits according to Russian tax rules. |
13 | 12 | |
14 | 13 | Examples: |
15 | | - >>> inn('7736050003') |
16 | | - # Output: True |
17 | | - >>> inn('781100086042') |
18 | | - # Output: True |
| 14 | + >>> ru_inn('500100732259') # Valid 12-digit INN |
| 15 | + True |
| 16 | + >>> ru_inn('7830002293') # Valid 10-digit INN |
| 17 | + True |
| 18 | + >>> ru_inn('1234567890') # Invalid INN |
| 19 | + ValidationFailure(func=ru_inn, args={'value': '1234567890'}) |
19 | 20 | |
20 | 21 | Args: |
21 | | - value: |
22 | | - Individual tax number string to validate |
23 | | - |
24 | | - Returns: |
25 | | - (Literal[True]): If `value` is a valid russian individual tax number. |
26 | | - (ValidationError): If `value` is an invalid russian individual tax number. |
| 22 | + value: Russian INN string to validate. Can contain only digits. |
27 | 23 | |
28 | 24 | Returns: |
| 25 | + (Literal[True]): If `value` is a valid Russian INN. |
| 26 | + (ValidationError): If `value` is an invalid Russian INN. |
29 | 27 | |
| 28 | + Note: |
| 29 | + The validation follows the official algorithm: |
| 30 | + - For 10-digit INN: checks 10th control digit |
| 31 | + - For 12-digit INN: checks both 11th and 12th control digits |
30 | 32 | """ |
31 | 33 | if not value: |
32 | 34 | return False |
|