Skip to content

Instantly share code, notes, and snippets.

@nyancodeid
Last active January 10, 2023 15:01
Show Gist options
  • Save nyancodeid/cc5a035f1e401b44dfdb8c8bfab4f3ce to your computer and use it in GitHub Desktop.
Save nyancodeid/cc5a035f1e401b44dfdb8c8bfab4f3ce to your computer and use it in GitHub Desktop.
Prefix Provider Indonesia in Javascript
function parseOperator(phone) {
var OperatorPrefix = {
telkomsel: ["0812","0813","0821","0822","0852","0853","0823","0851"],
indosat: ["0814","0815","0816","0855","0856","0857","0858"],
tri: ["0895","0896","0897","0898","0899"],
smartfren: ["0881","0882","0883","0884","0885","0886","0887","0888","0889"],
xl: ["0817","0818","0819","0859","0877","0878"],
axis: ["0838","0831","0832","0833"],
bolt: ["0999", "0998"]
}
if (phone.length > 13) return {
operator: null
}
for (var name in OperatorPrefix) {
var _operator = OperatorPrefix[name];
for (var index in _operator) {
if (phone.startsWith(_operator[index])) return {
operator: name,
prefix: _operator[index],
phone: phone
}
}
}
return {
operator: null
}
}
var ops = parseOperator("08966778890");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment