Skip to content

parse(id)

完整解析身份证信息。

函数签名

typescript
interface IDCardInfo {
  isValid: boolean           // 是否有效
  provinceCode: string       // 省份编码
  province: string           // 省份名称
  birthDate: string          // 出生日期 (YYYY-MM-DD)
  gender: 'male' | 'female'  // 性别
  age: number                // 年龄
  fifteenDigit: string | null // 15位身份证
  eighteenDigit: string | null // 18位身份证
}

function parse(id: string): IDCardInfo

参数

参数类型说明
idstring身份证号码

返回值

返回 IDCardInfo 对象,包含解析结果。

在线演示

代码示例

typescript
import { parse } from 'china-id-card'

const result = parse('622922197808118498')
// {
//   isValid: true,
//   province: '甘肃省',
//   birthDate: '1978-08-11',
//   gender: 'male',
//   age: 47,
//   eighteenDigit: '622922197808118498',
//   fifteenDigit: null
// }

基于 GB 11643-1999 标准