Created
November 30, 2020 12:54
-
-
Save edsonmsantos/7ec7f6b835c904b7a9cebc43353d69ea to your computer and use it in GitHub Desktop.
[Valida telefone] #js #javascript
This file contains hidden or 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
function isPhoneValid(phone) { | |
const ddd = ["51", "53", "54", "55", "47", "48", "49", "41", "42", "43", "44", "45", "46", "67", "65", "66", "69", "68", "92", "97", "91", "93", "94", "96", "95", "98", "99", "63", "61", "62", "64", "86", "89", "85", "88", "84", "83", "81", "87", "82", "79", "27", "28", "21", "22", "24", "71", "73", "74", "75", "77", "31", "32", "33", "34", "35", "37", "38", "11", "12", "13", "14", "15", "16", "17", "18", "19"] | |
if (phone.length !== 10 && phone.length !== 11) { | |
return false; | |
} | |
let phoneDDD = phone.substring(0, 2); | |
if (ddd.indexOf(phoneDDD) !== -1) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment