Expand description
Chinese Indentity Card Utilities
This package provides utilities to validate ID number, to extract detailed ID information, to upgrade ID number from 15-digit to 18-digit, to generate fake ID number, and some related functions for HongKong/Macau/Taiwan ID.
Examples
use idcard::{Identity, fake, Gender};
let id = Identity::new("632123820927051");
// Determines whether the ID number is valid.
assert_eq!(id.is_valid(), true);
// Gets properties
let number = id.number();
let gender = id.gender();
let age = id.age();
let birth_date = id.birth_date();
let region = id.region();
// and so on...
// Upgrades an ID number from 15-digit to 18-digit.
let id18 = idcard::upgrade("310112850409522").unwrap();
assert_eq!(&id18, "310112198504095227");
// Validates an ID number.
assert_eq!(idcard::validate("230127197908177456"), true);
// Generates a random fake ID number using the given options.
let opts = fake::FakeOptions::new()
.region("3301")
.min_year(1990)
.max_year(2000)
.female();
match fake::rand_with(&opts) {
Ok(num) => println!("{}", num),
Err(e) => println!("{}", e),
}
For more information ,please read the API documentation.
Modules
- Utilities for generating fake ID numbers
- Utilities for Hong Kong Identity Card
- Utilities for Macau Identity Card
- Region query utilities(only includes mainland data)
- Utilities for Taiwan Identity Card
Structs
- An object representation of the Chinese ID.
Enums
- Custom error type.
- The type of demographic genders
Functions
- Returns the Chinese Era by the given year, the given year should not be less than 1000.
- Returns the Chinese Zodiac animal by the given year, the given year should not be less than 1000.
- Returns the constellation by the given month and day.
- Upgrades a Chinese ID number from 15-digit to 18-digit.
- Validates a Chinese ID number(only supports 15/18-digit).