Monday, August 23, 2010

ServerSide Email Validator

In my last post i have written Javascript function for email validation. In this i will be discussing about ServerSide Email Validator. For application to be safe it is necessary to have both client and server side validators.
Steps for implementing ServerSide Email Validator
1. In jsp define the email component in the following way
  <h:outputLabel id="lb_MAIL_ID" value="Mail ID:" styleClass="label"/>
<h:inputText id="tf_MAIL_ID" autocomplete="off" value="#{userlogin.tf_MAIL_ID}" />
2. In java class get email component value and apply serverside email validator for it as shown below

/*
* Getting the tf_MAIL_ID component value
*/
String emailId = (String) getTf_MAIL_ID().toString();
 if (emailId == null || !emailId.matches("^[A-z0-9_\\-\\.]+[@][A-z0-9_\\-]+([.][A-z0-9_\\-]+)+[A-z]{2,4}")) {
             System.out.println("Please enter Valid Email-Id");
        }

Instead of  using  System.out.println you can use PopUp AlertMessagebox for JSF  as it clear idea for the user who is using it. 

JSF Related topics: JCaptcha in JSF, Integrating Richfaces with JSF,Getting client and server sessionId in JSF,PopUp AlertMessagebox for JSF and more.....

No comments:

Post a Comment