Skill: freedompixels/cn-id-validator (version 1.1.0)

--- slug: cn-id-validator name: Cn Id Validator version: "1.0.0" description: "cn id validator" keywords: tool, utility license: MIT-0 tags: - tools --- # Chinese ID Validator Validate Chinese ID numbers (18-digit and 15-digit formats) and extract information. ## Features - Validate 18-digit ID numbers (with checksum verification) - Validate 15-digit ID numbers (with birth date check) - Extract birth date from ID number - Extract gender from ID number - Extract region code from ID number - Pure Python, no external dependencies ## ID Number Format ### 18-digit Format (1999-present) - 1-6: Region code - 7-14: Birth date (YYYYMMDD) - 15-17: Sequential code (odd=male, even=female) - 18: Check digit (0-10, where 10=X) ### 15-digit Format (1985-1999) - 1-6: Region code - 7-12: Birth date (YYMMDD, assumed 19xx) - 13-15: Sequential code (odd=male, even=female) ## Usage ```bash python3 scripts/id_validator.py --id 110101199003074416 ``` ## Example Output ```json { "valid": true, "region": "110101", "birthday": "1990-03-07", "gender": "男" } ``` ## Validation Rules 1. Length must be 15 or 18 digits 2. Birth date must be a valid calendar date 3. For 18-digit IDs: checksum must be correct 4. Region code must be a valid Chinese administrative region ## Common Region Codes | Code | Region | |------|--------| | 110000 | 北京市 | | 310000 | 上海市 | | 440000 | 广东省 | | 320000 | 江苏省 | | 330000 | 浙江省 | ## Use Cases - User registration form validation - Identity verification in business processes - Age-based access control - Demographic data analysis ## Notes - This tool validates format and checksum only - It does not verify against government databases - Region codes are not fully validated (only format checked) - Results are for reference only ## Technical Details - Language: Python 3 - Dependencies: None (standard library only) - License: MIT-0

path: scripts/id_validator.py
content: #!/usr/bin/env python3
import argparse, json, sys, re

def validate_id18(id18):
    if len(id18) != 18:
        return False
    # Check birth date
    try:
        from datetime import datetime
        y, m, d = int(id18[6:10]), int(id18[10:12]), int(id18[12:14])
        datetime(y, m, d)
    except:
        return False
    # Check code
    factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    checkcodes = "10X98765432"
    total = sum(int(id18[i]) * factors[i] for i in range(17))
    return checkcodes[total % 11] == id18[17]

def validate_id15(id15):
    if len(id15) != 15:
        return False
    try:
        from datetime import datetime
        y, m, d = int("19" + id15[6:8]), int(id15[8:10]), int(id15[10:12])
        datetime(y, m, d)
        return True
    except:
        return False

def parse_id(idno):
    if len(idno) == 18 and validate_id18(idno):
        region = idno[:6]
        gender_code = int(idno[16])
        y, m, d = idno[6:10], idno[10:12], idno[12:14]
    elif len(idno) == 15 and validate_id15(idno):
        region = idno[:6]
        gender_code = int(idno[14])
        y, m, d = "19" + idno[6:8], idno[8:10], idno[10:12]
    else:
        return None
    return {"region": region, "birthday": f"{y}-{m}-{d}", "gender": "男" if gender_code % 2 == 1 else "女"}

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--id", required=True)
    args = parser.parse_args()
    result = parse_id(args.id)
    if result:
        print(json.dumps({"valid": True, **result}, ensure_ascii=False, indent=2))
    else:
        print(json.dumps({"valid": False, "error": "Invalid Chinese ID"}))
        sys.exit(1)

if __name__ == "__main__":
    main()


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)