Skip to contents

Check if the Chinese ID number complies with the GB 11643-1999 standard.

Usage

check_id(x, return = "logical")

Arguments

x

A character vector containing Chinese ID numbers to be checked for compliance with the GB 11643-1999 standard.

return

A character string used to specific the type of result returned. Options are 'logical', 'date', 'areacode', 'formatted'. Options include:

  • 'logical': Logical vector (default). Indicates whether each input ID number complies with the standard (TRUE for compliant, FALSE for non-compliant).

  • 'date': Date vector representing birth date contained in the ID number.

  • 'areacode': Character vector containing administrative region codes extracted from the ID number.

  • 'formatted': Character vector containing formatted ID numbers.

Value

A logical vector indicating whether each input ID number complies with the standard (TRUE for compliant, FALSE for non-compliant), or other types of information based on the 'return' parameter.

Examples

ids <- c("412726198407240038", "110101199003070975",
         "310101199001010101", "440101199102030303")
check_id(ids)
#> [1]  TRUE FALSE FALSE FALSE
check_id(ids, return = "date")
#> [1] "1984-07-24" "1990-03-07" "1990-01-01" "1991-02-03"
check_id(ids, return = "areacode")
#> [1] "412726" "110101" "310101" "440101"
check_id(ids, return = "formatted")
#> [1] "412726198407240038" NA                   NA                  
#> [4] NA