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
Functions
Section titled “Functions”| 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 -.
Parsed fields
Section titled “Parsed fields”| 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.
Errors
Section titled “Errors”length, charset, region (district code does not exist), date (not a real date), serial.
Example
Section titled “Example”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))}import * as nik from "nusaindex/nik";
console.log(nik.isValid("7502010706599583"));
const parsed = nik.parse("7502010706599583");if (parsed.ok) { const { districtCode, birthDate, sex, serial } = parsed.value; console.log(districtCode, birthDate, sex, serial);}
const older = nik.parseAt("3315101003154137", 2010);if (older.ok) { console.log(older.value.birthDate);}
const formatted = nik.format("7502 0107 0659 9583");if (formatted.ok) { console.log(formatted.value);}
console.log(nik.mask("7502010706599583"));
const invalid = nik.parse("7502013206599583");console.log(!invalid.ok && invalid.error.code === "date");true75.02.01 1959-06-07 male 95831915-03-107502010706599583************9583true© 2026 Haikal Mumtaz