Thursday 21 February 2013

Java code for email validation in ADF

## Code for email validation

public void emailValidator(FacesContext facesContext, UIComponent uIComponent, Object object) {
       if(object!=null){
           String name=object.toString();
           String expression="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
           CharSequence inputStr=name;
           Pattern pattern=Pattern.compile(expression);
           Matcher matcher=pattern.matcher(inputStr);
           String msg="Email is not in Proper Format";
           if(matcher.matches()){
              
           }
           else{
               throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,msg,null));
           }
       }
   }

2 comments: