Portlet Factory, Version 6.1.2
A Validate Method Implementation
The validate method follows the process of analyzing an expression and calling the appropriate method to perform the actual operation; in this case validating that the user used only numeric characters for the phone number input.
public boolean validate(String value, String expression) { boolean result = false; if(expression.equals(VALIDATEPHONE)) { result = validatePhoneNumber(value); return result; }The validatePhoneNumber method checks to see if the value argument is only made up of numeric characters:
boolean validatePhoneNumber(String value) { boolean result = true; char ch; for(int index = 0; index < value.length(); index++) { ch = value.charAt(index); if (ch<48 || ch>57) { result=false; setErrorMessage("Phone numbers cannot include letters."); return result; }
An Error Message for Failed Validation
In the code example above, notice that if a character was found to be outside of the ASCII range of numeric characters, the code calls the setErrorMessage method, setting the message string with an appropriate error message.
Parent topic: About creating a formatter class
Library | Support |