Created
March 29, 2013 19:59
-
-
Save brainv/5273230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// parse philippine mobile network operator from wikipedia | |
// http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Philippines | |
function ph_mno(msisdn) { | |
var links = document.querySelectorAll('ul li a'); | |
var operator = new Array(); | |
for (i=0; i<links.length; i++) { | |
var string = links[i].parentNode.innerText; | |
if (string.match(/(globe|next|smart|sun|express)/ig)) { | |
name = string.replace(/(\W)*:.*/g, "$1").replace(/(.*)\n.*/g, "$1"); | |
num_range = string.replace(/[a-zA-Z\s:]*/g, "").replace("()", ",").split(','); | |
operator[name] = num_range; | |
} | |
} | |
for (key in operator) { | |
for (i=0; i<operator[key].length; i++) { | |
if (!operator[key][i]) | |
continue; | |
var pattern = new RegExp("^(63|0)" + operator[key][i]); | |
if (msisdn.match(pattern)) { | |
return key; | |
} | |
} | |
} | |
return "Unknown operator"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment