-1

If I have phone number ranges such as 5555555555-5599 5555550000-0003 5555550005-0007, my mission is to have it return all results without using a server. Is it possible for it to return without a server a result that would look like:

5555555555
5555555556
5555555557
/* etc */

My previous post about javascript has helped me up to this point but I wanted to rehaul the whole site.

Javascript dashes in phone number

If you could point me in the right direction, I would really appreciate it. I'm just having a mind block right now if this is even possible.

Community
  • 1
  • 1
traveler84
  • 453
  • 2
  • 4
  • 15

1 Answers1

1

Given a single phone range in the form of "xxxxxxyyyy-zzzz", split the whole string on the dash and the first part of the string at the 6th index. This yields three strings "xxxxxx", "yyyy", and "zzzz". Using a for loop, you can create an array of phone numbers by concatenating the prefix "xxxxxx" onto the range "yyyy"-"zzzz":

// Get an array from a given range "xxxxxxyyyy-zzzz"
function fromRange(range) {
  var phoneNumArray = [];
  var prefix = range.substring(0,5);
  var suffixRange = range.split("-");
  for (var suffix = suffixRange[0].substring(4, -1);suffix < suffixRange[1];suffix++) {
    phoneNumArray.push(prefix + suffix);
  }
  return phoneNumArray;
}

Try it in JSFiddle.

Nielsvh
  • 1,151
  • 1
  • 18
  • 31