Skip to content

Instantly share code, notes, and snippets.

@tgmarinho
Created September 21, 2017 18:17
Show Gist options
  • Save tgmarinho/6c30eec82328db7558c345269cb2f9c2 to your computer and use it in GitHub Desktop.
Save tgmarinho/6c30eec82328db7558c345269cb2f9c2 to your computer and use it in GitHub Desktop.
// Nome, Tipo de campo, placeholder, Validacao(Inteface)
public enum TipoPessoa {
FISICA("Física", "CPF", "000.000.000-00", CpfGroup.class) {
@Override
public String formatar(String cpfOuCnpj) {
return cpfOuCnpj.replaceAll("(\\d{3})(\\d{3})(\\d{3})", "$1.$2.$3-");
}
},
JURIDICA("Jurídica", "CNPJ", "00.000.000/0000-00", CnpjGroup.class) {
@Override
public String formatar(String cpfOuCnpj) {
return cpfOuCnpj.replaceAll("(\\d{2})(\\d{3})(\\d{3})(\\d{4})", "$1.$2.$3/$4-");
}
};
private String descricao;
private String documento;
private String mascara;
private Class<?> grupo;
TipoPessoa(String descricao, String documento, String mascara, Class<?> grupo) {
this.descricao = descricao;
this.documento = documento;
this.mascara = mascara;
this.grupo = grupo;
}
public abstract String formatar(String cpfOuCnpj);
public String getDescricao() {
return descricao;
}
public String getDocumento() {
return documento;
}
public String getMascara() {
return mascara;
}
public Class<?> getGrupo() {
return grupo;
}
public static String removerFormatacao(String cpfOuCnpj) {
return cpfOuCnpj.replaceAll("\\.|-|/", "");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment