br.com.jarch.faces.validator.PhoneValidator Maven / Gradle / Ivy
package br.com.jarch.faces.validator;
import br.com.jarch.core.exception.ValidationException;
import br.com.jarch.core.util.BundleUtils;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
@FacesValidator("phoneValidator")
public class PhoneValidator implements Validator {
public static final int EIGTH = 8;
public static final int NINE = 9;
@Override
public void validate(FacesContext arg0, UIComponent arg1, Object value) {
String numeroTelefone = value.toString();
numeroTelefone = numeroTelefone.replace("(", "");
numeroTelefone = numeroTelefone.replace(")", "");
numeroTelefone = numeroTelefone.replace("-", "");
numeroTelefone = numeroTelefone.replace(" ", "");
Integer telefone = Integer.valueOf(numeroTelefone);
if (telefone.toString().length() > NINE || telefone.toString().length() < EIGTH) {
throw new ValidationException(BundleUtils.messageBundle("message.numeroTelefoneInvalido"));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy