Anil's Blog is Best Viewed on GOOGLE CHROME

Saturday, October 2, 2010

How to Restrict user from entering special characters using Regular expressions- OAF

In this exercise we have taken hello world page shipped with Toolbox Tutorial.

We are going to restrict user from entering special character on page. For this we have written the code in controller processFormRequest Method & handle the logic on Go Button.

Hence When a user clicks on Go button a validation is done for special characters being entered by user if it is then an error message is shown on the screen as shown in the picture else it will display confirmation message on screen.







Here is the code snippet to handle this validation .

Controller Code

package oracle.apps.fnd.framework.toolbox.tutorial.webui;
import java.util.regex.*;

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {

    super.processFormRequest(pageContext, webBean);

    if (pageContext.getParameter("Go") != null)
    {
      String userContent = pageContext.getParameter("HelloName");
      String message = "Hello, " + userContent + "!";

     Pattern p = Pattern.compile("[^a-zA-Z0-9\\s]");
     Matcher m = p.matcher(userContent);

     if (m.find())
     {
      throw new OAException("Special Characers not Allowed", OAException.ERROR);
     }

      else
      {
        throw new OAException(message, OAException.INFORMATION);
    }

    }

Thanks
AJ

1 comment:

  1. Hi Anil,

    i have a reuirement very urgent.
    Requirement is as follows:
    "i have a MessageTextInput Field item which should not allow special symbols(like {,},;,",?,etc) so when user enters any special symbol immediately we should prompt him/her that "you cannot enter special characters like :,",|,\,}" message". (instead of after pressing GO button)
    Plz help me in this regard.

    Thanks,
    Raja.

    ReplyDelete

Note: Only a member of this blog may post a comment.