List of usage examples for org.apache.commons.validator GenericValidator matchRegexp
public static boolean matchRegexp(String value, String regexp)
Checks if the value matches the regular expression.
From source file:org.springmodules.commons.validator.FieldChecks.java
/** * Checks if the field matches the regular expression in the field's mask * attribute.// w ww. j ava 2 s .co m * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed. * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return true if field matches mask, false otherwise. */ public static boolean validateMask(Object bean, ValidatorAction va, Field field, Errors errors) { String mask = field.getVarValue("mask"); String value = extractValue(bean, field); try { if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.matchRegexp(value, mask)) { rejectValue(errors, field, va); return false; } else { return true; } } catch (Exception e) { log.error(e.getMessage(), e); } return true; }
From source file:org.springmodules.validation.commons.FieldChecks.java
/** * Checks if the field matches the regular expression in the field's mask * attribute.//from ww w . ja va 2 s. c o m * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed. * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return true if field matches mask, false otherwise. */ public static boolean validateMask(Object bean, ValidatorAction va, Field field, Errors errors) { String mask = field.getVarValue("mask"); String value = FieldChecks.extractValue(bean, field); try { if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.matchRegexp(value, mask)) { FieldChecks.rejectValue(errors, field, va); return false; } else { return true; } } catch (Exception e) { FieldChecks.log.error(e.getMessage(), e); } return true; }