Mobile number validation in javascript

Viewed 37

I have this mobile number format

+14354444744

It can accept upto 15 digits and + is mandatory

no other characters or special characters should be there

function phonenumber(inputtxt) {
  var phoneno = /^([+]\d{2})?\d{15}$/;
  if(inputtxt.value.match(phoneno)) {
    return true;
  }
  else {
    return false;
  }
}

Any solution thanks.

1 Answers
function phonenumber(inputtxt) {
  if(inputtxt[0]==="+") {
      number=inputtxt.substring(1,inputtxt.lenght);
      if(Number(number)){
          if (number.length >= 15){
              return true;
          } else {
              return false;
          }
      } else {
              return false;
          }
  } else {
    return false;
  }
}
console.log(phonenumber("+1433f3333333"));
Related