Skip to content

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.

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 ).

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.

length, charset, country (country code other than +62), prefix.

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))
}
Output
true
+628595257171 mobile XL XLSmart
+62213456789 fixed 021
+628595257171
https://wa.me/628595257171
+62*******171
true