Created
July 26, 2017 09:52
-
-
Save SakaDream/9dc61acb0af6619c4aced355d698f112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sakadream.jsf.validator; | |
import javax.faces.application.FacesMessage; | |
import javax.faces.component.UIComponent; | |
import javax.faces.context.FacesContext; | |
import javax.faces.validator.FacesValidator; | |
import javax.faces.validator.Validator; | |
import javax.faces.validator.ValidatorException; | |
/** | |
* Created by Phan Ba Hai on 21/07/2017. | |
*/ | |
@FacesValidator("com.sakadream.jsf.validator.PhoneValidator") | |
public class PhoneValidator implements Validator { | |
@Override | |
public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException { | |
if(!o.toString().startsWith("0")) { | |
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Phone validation failed: ", "Invalid Phone Number!")); | |
} else if(o.toString().length() != 10 && o.toString().length() != 11) { | |
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Phone validation failed: ", "Phone number must be 10 or 11 numbers!")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment