Skip to content

Instantly share code, notes, and snippets.

@kaweski
Created August 28, 2018 17:48
Show Gist options
  • Save kaweski/cfe8fcbf2ca8afba24d2cec9dc32ea5d to your computer and use it in GitHub Desktop.
Save kaweski/cfe8fcbf2ca8afba24d2cec9dc32ea5d to your computer and use it in GitHub Desktop.
Valida telefones do Brasil com DDD, o 9º dígito e obrigatoriamente contendo 9 dígitos, mais espaços e caracteres de separação.
let regex = /^\([1-9]{2}\) 9 [7-9][0-9]{3}\-[0-9]{4}$/;
if( regex.test(c.value) ) {
return null;
} else {
return { phoneError: true };
}
@brunopulis
Copy link

Maybe the code can be refactoring, like this:

let regex = /^\([1-9]{2}\) 9 [7-9][0-9]{3}\-[0-9]{4}$/;
return regex.test(c.value) ? null : phoneError: true;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment