com.evasion.common.validator.EmailValidator Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.common.validator;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
/**
*
* @author sebastien.glon
*/
@FacesValidator(value = "emailValidator")
public class EmailValidator implements Validator{
@Override
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
String email = (String) o;
if (!email.matches(".+@.+\\.[a-z]+")) {
((UIInput)uic).setValid(false);
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Email", ""));
}
}
}