Thursday, January 19, 2012

ADF 11G : How to Validate the email in ADF ?

ADF 11G : How to Validate the email in ADF ?


There are multiple way to handle the validation in ADF framework. Few of them are mentioned here.

APPROACH-1











APPROACH-2











    /**
     * Validation method for Email.
     */
    public boolean validateEmail(String email) {
        System.out.println(email);
        String expression="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
                   CharSequence inputStr=email;
                   Pattern pattern=Pattern.compile(expression);
                   Matcher matcher=pattern.matcher(inputStr);
                   String msg="Email is not in Proper Format";
                   if(matcher.matches()){
                      return true;
                   }
                   else{
                      return false;                      
                   }

        }

----------------------------------------------------------------------------------
APPROACH-3

public boolean validateEmail(String email) {
int i=0;
i= email.indexOf("@");
if(i >= 0)
return true;
else
return false; }
/** * Validation method for ConfirmEmail. */
public boolean validateConfirmEmail(String confirmemail) {
if(getEmail().equalsIgnoreCase(confirmemail))
return true;
else
return false;
}
-------------------------------------------------------------------------------------
if(!emailId.contains("@")) {

FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("Email is not valid.");
message.setDetail("Email is not valid.");
facesContext.addMessage("userForm:Email", message);
throw new ValidatorException(message);

}

*********************************************
int dot1pos = mData.indexOf('.');
int dot2pos = mData.lastIndexOf('.');
int ln = mData.length();
if (dot1pos != 3 dot2pos != 7 ln != 12) {
throw new DataCreationException(null,"Invalid phone number - format is xxx.xxx.xxxx",null);

}