# tckimlik
[](#contributors-)
[](https://crates.io/crates/tckimlik)
[](https://docs.rs/tckimlik)
[](https://github.com/trananhtung/tckimlik/actions/workflows/ci.yml)
[](#license)
**Validate Turkish national identification numbers (T.C. Kimlik No.).**
The Turkish Identification Number (*Türkiye Cumhuriyeti Kimlik Numarası*) is an 11-digit
number assigned to every citizen of Turkey, whose last two digits are check digits. A
faithful Rust port of the algorithm used by
[`python-stdnum`](https://arthurdejong.org/python-stdnum/).
- **Zero dependencies**, **`#![no_std]`**
- `is_valid`, `validate`, `calc_check_digits`, `compact`
- Differential-tested against `python-stdnum` (60k cases)
## Install
```toml
[dependencies]
tckimlik = "0.1"
```
## Usage
```rust
use tckimlik::{is_valid, validate, calc_check_digits};
assert!(is_valid("17291716060"));
assert!(!is_valid("17291716050")); // wrong check digit
assert!(!is_valid("07291716092")); // must not start with 0
assert_eq!(validate(" 17291716060 ").unwrap(), "17291716060"); // trims whitespace
assert_eq!(calc_check_digits("172917160").unwrap(), "60"); // the two check digits
```
The number is valid when it has 11 digits, does not start with `0`, and its last two digits
equal `check1 = (10 - Σ wᵢ·dᵢ) mod 10` and `check2 = (check1 + Σ dᵢ) mod 10` computed over the
first nine digits (weights `3,1,3,1,…`).
## Contributors ✨
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the [emoji key](https://allcontributors.org/docs/en/emoji-key) for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/trananhtung"><img src="https://avatars.githubusercontent.com/u/30992229?v=4?s=100" width="100px;" alt="Tung Tran"/><br /><sub><b>Tung Tran</b></sub></a><br /><a href="https://github.com/trananhtung/./commits?author=trananhtung" title="Code">💻</a> <a href="#maintenance-trananhtung" title="Maintenance">🚧</a></td>
</tr>
</tbody>
</table>
## License
Licensed under either of [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE) at your option.