Crate idcard[][src]

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...

// Converts the value to a JSON string.
println!("{}", id.to_json_string(true));

// 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)
    .gender(Gender::Female);
match fake::rand_with_opts(&opts) {
    Ok(num) => println!("{}", num),
    Err(e) => println!("{}", e),
}

For more information ,please read the API documentation.

Modules

fake

Utilities for generating fake ID numbers

hk

Utilities for Hong Kong Identity Card

mo

Utilities for Macau Identity Card

region

Region query utilities(only includes mainland)

tw

Utilities for Taiwan Identity Card

Structs

Identity

An object representation of the Chinese ID.

Enums

Error

Custom error type.

Gender

The type of demographic genders

Functions

chinese_era

Returns the Chinese Era by the given year, the given year should not be less than 1000.

chinese_zodiac

Returns the Chinese Zodiac animal by the given year, the given year should not be less than 1000.

constellation

Returns the constellation by the given month and day.

upgrade

Upgrades a Chinese ID number from 15-digit to 18-digit.

validate

Validates a Chinese ID number(only supports 15/18-digit).