1 20 package org.enhydra.barracuda.core.forms; 21 22 import java.util.*; 23 24 29 public class FormUtil { 30 31 57 public static String assertMinMax(String field, String fieldDescr, int min, int max) throws ValidationException { 58 if (field==null) field = ""; 59 else field = field.trim(); 60 if (min!=-1) assertTrue(fieldDescr+" must be at least "+min+" chars in length -- Please re-enter!", field.length()>=min); 61 if (max!=-1) assertTrue(fieldDescr+" may not exceed "+max+" chars in length -- Please re-enter!", field.length()<=max); 62 return field; 63 } 64 65 73 public static void assertTrue(String errmsg, boolean expression) throws ValidationException { 74 if (!expression) throw new ValidationException(null, errmsg); 75 } 76 77 78 } 79 | Popular Tags |