Phone numbers
- +62Country code
- Indonesia
- 859Operator prefix
- XL, XLSmart
- 5257171Subscriber number
Well-formed
Accepts 08…, 628…, +62 8…, and fixed-line numbers with an area code such as (021) 3456 789. Mobile prefixes and fixed-line area codes follow Permenkominfo 14/2018.
Functions
Section titled “Functions”| Go | TypeScript | Returns |
|---|---|---|
phone.Valid(s) |
phone.isValid(s) |
Whether s is a well-formed Indonesian number |
phone.Parse(s) |
phone.parse(s) |
The fields below |
phone.Format(s) |
phone.format(s) |
E.164, such as +628595257171 |
phone.WhatsAppLink(s) |
phone.whatsappLink(s) |
https://wa.me/628595257171 |
phone.Mask(s) |
phone.mask(s) |
+62 and the last 3 digits visible |
Accepted separators: space, -, ., ( and ).
Parsed fields
Section titled “Parsed fields”| Field (JSON) | Example | Notes |
|---|---|---|
e164 |
+628595257171 |
|
national |
08595257171 |
|
type |
mobile |
mobile or fixed |
prefix |
0859 |
Mobile only |
brand |
XL |
Mobile only: Telkomsel, IM3, Tri, XL, AXIS, or Smartfren |
operator |
XLSmart |
Mobile only: Telkomsel, Indosat Ooredoo Hutchison, or XLSmart |
areaCode |
021 |
Fixed line only, see region.ByAreaCode for the regions |
Mobile numbers have 9 to 12 digits after the leading 0. Fixed-line numbers have 8 to 11 including the area code. Prefixes that were revoked or never allocated, such as 0827, 0828 and 0879, fail with prefix.
Errors
Section titled “Errors”length, charset, country (country code other than +62), prefix.
Example
Section titled “Example”package main
import ( "errors" "fmt"
"github.com/haikalmumtaz233/nusaindex/phone")
func main() { fmt.Println(phone.Valid("0859-5257-171"))
mobile, err := phone.Parse("0859-5257-171") if err == nil { fmt.Println(mobile.E164, mobile.Type, mobile.Brand, mobile.Operator) }
fixed, err := phone.Parse("(021) 3456 789") if err == nil { fmt.Println(fixed.E164, fixed.Type, fixed.AreaCode) }
formatted, err := phone.Format("+62 859 5257 171") if err == nil { fmt.Println(formatted) }
link, err := phone.WhatsAppLink("0859-5257-171") if err == nil { fmt.Println(link) }
fmt.Println(phone.Mask("0859-5257-171"))
_, err = phone.Parse("+1 202 555 0100") fmt.Println(errors.Is(err, phone.ErrCountry))}import * as phone from "nusaindex/phone";
console.log(phone.isValid("0859-5257-171"));
const mobile = phone.parse("0859-5257-171");if (mobile.ok) { const { e164, type, brand, operator } = mobile.value; console.log(e164, type, brand, operator);}
const fixed = phone.parse("(021) 3456 789");if (fixed.ok) { console.log(fixed.value.e164, fixed.value.type, fixed.value.areaCode);}
const formatted = phone.format("+62 859 5257 171");if (formatted.ok) { console.log(formatted.value);}
const link = phone.whatsappLink("0859-5257-171");if (link.ok) { console.log(link.value);}
console.log(phone.mask("0859-5257-171"));
const foreign = phone.parse("+1 202 555 0100");console.log(!foreign.ok && foreign.error.code === "country");true+628595257171 mobile XL XLSmart+62213456789 fixed 021+628595257171https://wa.me/628595257171+62*******171true© 2026 Haikal Mumtaz