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);
- }
- }
No comments:
Post a Comment