-
-
Save MarceloRab/6fdf0ec2d977d253d69c0bb02ff61b63 to your computer and use it in GitHub Desktop.
Validar Celular para contato WhatsApp
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
const numberCel = '554791517799'; | |
function addNine(number) { | |
if (numberCel.slice(0, -numberCel.length + 2) !== '55') { | |
//if (numberCel[0] + numberCel[1] !== '55') { | |
// numberCel.slice(0,-numberCel.length +2) | |
return number; | |
} | |
if ( | |
numberCel[4] === '2' || | |
numberCel[4] === '3' || | |
numberCel[4] === '4' || | |
numberCel[4] === '5' | |
) { | |
return number; | |
} | |
var volta = 0; | |
var textVolta = ''; | |
if (number.length < 13) { | |
for (let member in number) { | |
textVolta += number[member]; | |
if (volta === 3) { | |
textVolta += '9'; | |
} | |
volta++; | |
} | |
} else { | |
return number; | |
} | |
return textVolta; | |
} | |
console.log(addNine(numberCel)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment