1 21 22 package org.apache.commons.validator; 23 24 import java.io.Serializable ; 25 import java.util.Locale ; 26 27 import org.apache.oro.text.perl.Perl5Util; 28 29 32 public class GenericValidator implements Serializable { 33 34 37 private static final UrlValidator urlValidator = new UrlValidator(); 38 39 42 private static final CreditCardValidator creditCardValidator = 43 new CreditCardValidator(); 44 45 51 public static boolean isBlankOrNull(String value) { 52 return ((value == null) || (value.trim().length() == 0)); 53 } 54 55 61 public static boolean matchRegexp(String value, String regexp) { 62 if (regexp == null || regexp.length() <= 0) { 63 return false; 64 } 65 66 Perl5Util matcher = new Perl5Util(); 67 return matcher.match("/" + regexp + "/", value); 68 } 69 70 75 public static boolean isByte(String value) { 76 return (GenericTypeValidator.formatByte(value) != null); 77 } 78 79 84 public static boolean isShort(String value) { 85 return (GenericTypeValidator.formatShort(value) != null); 86 } 87 88 93 public static boolean isInt(String value) { 94 return (GenericTypeValidator.formatInt(value) != null); 95 } 96 97 102 public static boolean isLong(String value) { 103 return (GenericTypeValidator.formatLong(value) != null); 104 } 105 106 111 public static boolean isFloat(String value) { 112 return (GenericTypeValidator.formatFloat(value) != null); 113 } 114 115 120 public static boolean isDouble(String value) { 121 return (GenericTypeValidator.formatDouble(value) != null); 122 } 123 124 133 public static boolean isDate(String value, Locale locale) { 134 return DateValidator.getInstance().isValid(value, locale); 135 } 136 137 148 public static boolean isDate(String value, String datePattern, boolean strict) { 149 return DateValidator.getInstance().isValid(value, datePattern, strict); 150 } 151 152 160 public static boolean isInRange(byte value, byte min, byte max) { 161 return ((value >= min) && (value <= max)); 162 } 163 164 172 public static boolean isInRange(int value, int min, int max) { 173 return ((value >= min) && (value <= max)); 174 } 175 176 184 public static boolean isInRange(float value, float min, float max) { 185 return ((value >= min) && (value <= max)); 186 } 187 188 196 public static boolean isInRange(short value, short min, short max) { 197 return ((value >= min) && (value <= max)); 198 } 199 200 208 public static boolean isInRange(long value, long min, long max) { 209 return ((value >= min) && (value <= max)); 210 } 211 212 220 public static boolean isInRange(double value, double min, double max) { 221 return ((value >= min) && (value <= max)); 222 } 223 224 228 public static boolean isCreditCard(String value) { 229 return creditCardValidator.isValid(value); 230 } 231 232 237 public static boolean isEmail(String value) { 238 return EmailValidator.getInstance().isValid(value); 239 } 240 241 248 public static boolean isUrl(String value) { 249 return urlValidator.isValid(value); 250 } 251 252 258 public static boolean maxLength(String value, int max) { 259 return (value.length() <= max); 260 } 261 262 268 public static boolean minLength(String value, int min) { 269 return (value.length() >= min); 270 } 271 272 274 280 public static boolean minValue(int value, int min) { 281 return (value >= min); 282 } 283 284 290 public static boolean minValue(long value, long min) { 291 return (value >= min); 292 } 293 294 300 public static boolean minValue(double value, double min) { 301 return (value >= min); 302 } 303 304 310 public static boolean minValue(float value, float min) { 311 return (value >= min); 312 } 313 314 320 public static boolean maxValue(int value, int max) { 321 return (value <= max); 322 } 323 324 330 public static boolean maxValue(long value, long max) { 331 return (value <= max); 332 } 333 334 340 public static boolean maxValue(double value, double max) { 341 return (value <= max); 342 } 343 344 350 public static boolean maxValue(float value, float max) { 351 return (value <= max); 352 } 353 354 } 355 | Popular Tags |