package ilarkesto.form.validator; import ilarkesto.form.ValidationException; /** * @author <A href="mailto:wi@koczewski.de">Witoslaw Koczewski </A> * @version 1 $Revision: 1.2 $ $Author: wko $ $Date: 2006/09/13 19:07:31 $ */ public class DecimalValidator implements Validator { private double min; private double max; public DecimalValidator(double min, double max) { this.min = min; this.max = max; } // overriding public String validate(String text) throws ValidationException { text = text.trim(); double i; try { i = Double.parseDouble(text.replace(',', '.')); } catch (NumberFormatException ex) { throw new ValidationException("Die Eingabe mu\u00DF eine Zahl sein. " + getMessage()); } if (i < min || i > max) throw new ValidationException(getMessage()); return text; } public String getMessage() { return "Der Wert mu\u00DF zwischen " + min + " und " + max + " liegen."; } }