Skip to content

NIK

32Province
Jawa Barat
73Regency or city
Kota Bandung
27District
Gedebage
570590Birth date and sex
17 May 1990, female (day + 40)
1349Serial number

Well-formed

Go TypeScript Returns
nik.Valid(s) nik.isValid(s) Whether s is a well-formed NIK
nik.Parse(s) nik.parse(s) The fields below
nik.ParseAt(s, year) nik.parseAt(s, year) Same, with the birth century relative to year
nik.Format(s) nik.format(s) 16 digits without separators
nik.Mask(s) nik.mask(s) Last 4 digits visible

Accepted separators: space, . and -.

Field (JSON) Example Notes
nik 16 digits Separators removed
provinceCode 75
regencyCode 75.02
districtCode 75.02.01 Checked against the region data, including historical codes
birthDate 1959-06-07 YYYY-MM-DD, the two-digit year resolves to the latest year not after the current year (or year in ParseAt)
sex male male or female
serial 9583 Never 0000

Parse does not load region names. Use region.FromNIK / region.fromNik to turn the district code into names.

length, charset, region (district code does not exist), date (not a real date), serial.

package main
import (
"errors"
"fmt"
"github.com/haikalmumtaz233/nusaindex/nik"
)
func main() {
fmt.Println(nik.Valid("7502010706599583"))
parsed, err := nik.Parse("7502010706599583")
if err == nil {
fmt.Println(parsed.DistrictCode, parsed.BirthDate, parsed.Sex, parsed.Serial)
}
older, err := nik.ParseAt("3315101003154137", 2010)
if err == nil {
fmt.Println(older.BirthDate)
}
formatted, err := nik.Format("7502 0107 0659 9583")
if err == nil {
fmt.Println(formatted)
}
fmt.Println(nik.Mask("7502010706599583"))
_, err = nik.Parse("7502013206599583")
fmt.Println(errors.Is(err, nik.ErrDate))
}
Output
true
75.02.01 1959-06-07 male 9583
1915-03-10
7502010706599583
************9583
true