This guy has explained it very well.
28 Ocak 2012 Cumartesi
JSF 1.2 Email Validation
In JSF 2.0 we have
@Pattern(regexp=".+@.+\\.[a-z]+",message="Username must be in e-mail format");
We define it just above the mailadress variable in Managedbean and life is so good. But inJSF1.2 we have to write our own mailValidator class. Here is how we can do it:
@Pattern(regexp=".+@.+\\.[a-z]+",message="Username must be in e-mail format");
We define it just above the mailadress variable in Managedbean and life is so good. But inJSF1.2 we have to write our own mailValidator class. Here is how we can do it:
- First of all, create a validator class :/**
* @author Burhan ARAS
*
*/
public class EmailValidator implements Validator {
/* (non-Javadoc)
* @see javax.faces.validator.Validator#validate(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
*/
@Override
public void validate(FacesContext facesContext, UIComponent uIComponent, Object object)
throws ValidatorException {
// TODO Auto-generated method stub
String enteredEmail = (String)object;
//Set the email pattern string
Pattern p = Pattern.compile(".+@.+\\\\.[a-z]+");
//Match the given string with the pattern
Matcher m = p.matcher(enteredEmail);
//Check whether match is found
boolean matchFound = m.matches();
if (!matchFound) {
FacesMessage message = new FacesMessage();
message.setDetail("Email geçersiz.");
message.setSummary("Kullanıcı adi e-mail formatında değil.");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
} - Secondly we should define this validator in faces-config.xml file. <validator>
<validator-id>emailvalidator</validator-id>
<validator-class>com.blog.util.EmailValidator</validator-class>
</validator> - And finally, we are gonna declare it in our preview file like html, jsf or whatever.
Etiketler:
annotation,
email validation,
jsf,
jsf 1.2,
pattern,
validation
5 Ocak 2012 Perşembe
EXCEL formatting
=CONCATENATE(REPT("0", 9 - LEN(A2)),A2," ",B2,REPT(" ",20 - LEN(B2))," ",C2,REPT("0",8 - LEN(C2))," ",REPT("0",2 - LEN(D2)),D2," ",REPT("0",9 - LEN(E2)),E2)
Kaydol:
Kayıtlar (Atom)