All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 (!UIInput.class.isInstance(uic)) {
           throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Component type not compatible", ""));
       }
       
       if (!email.matches(".+@.+\\.[a-z]+")) {
          ((UIInput)uic).setValid(false);
          throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Email", ""));
       }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy