Skip to content

Instantly share code, notes, and snippets.

@brunomarks7
Created December 25, 2021 02:03
Show Gist options
  • Save brunomarks7/6c13c10e1b2654ee3e9bd921b56e65a6 to your computer and use it in GitHub Desktop.
Save brunomarks7/6c13c10e1b2654ee3e9bd921b56e65a6 to your computer and use it in GitHub Desktop.
Validate brazilian phone / cellphone by national patterns (regex)
const checkPhonepattern = phone => {
// checa se o telefone é fixo com começo entre 2 e 5
// ou celular com 9 dig e começo entre 6 e 9
if ( (/^(?:(55\d{2})|\d{2})[2-5]\d{7}$/.test(phone)) || (/^(?:(55\d{2})|\d{2})[6-9]\d{8}$/.test(phone))) {
return true;
}else {
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment