mercredi 11 avril 2018

I need to take an inputted string, take the non-numeric characters out, and then if the string begins with a 1, remove the 1

function changeNumber(e) {
  var phoneNumber = e.replace(/\D/g, '');
  if (phoneNumber.startsWith("1")) {
    var finalNumber = phoneNumber.slice(0);
    return finalNumber;
  } else {
    return phoneNumber;
  };
};
console.log(changeNumber("+1 (234)-567.8995"));

Desired result should be: 2345678995 but I am getting 12345678995. It's like it's not running through the if statement.

Aucun commentaire:

Enregistrer un commentaire