Skip to content

Instantly share code, notes, and snippets.

@MarceloRab
Last active February 7, 2024 16:07
Show Gist options
  • Save MarceloRab/6fdf0ec2d977d253d69c0bb02ff61b63 to your computer and use it in GitHub Desktop.
Save MarceloRab/6fdf0ec2d977d253d69c0bb02ff61b63 to your computer and use it in GitHub Desktop.
Validar Celular para contato WhatsApp
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