A valid HCPCS code is:
Details
5 characters long
Begins with one of
[A-CEGHJ-MP-V0-9]
Followed by any 3 digits,
[0-9]{3}
, andEnds with one of
[AFMTU0-9]
Examples
x <- c('T1503', 'G0478', '81301', '69641', '0583F', '0779T', NA)
is_valid_hcpcs(x)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE FALSE
x[which(is_valid_hcpcs(x))]
#> [1] "T1503" "G0478" "81301" "69641" "0583F" "0779T"
try(is_valid_hcpcs("1164"))
#> Error in is_valid_hcpcs("1164") :
#> `hcpcs_code` must be 5 characters long.