List of usage examples for org.apache.commons.validator GenericValidator minLength
public static boolean minLength(String value, int min)
Checks if the value's length is greater than or equal to the min.
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate that a value contains at least a certain number of characters. * /*from w w w. j a v a2s . c om*/ * @param value * The value to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if the value is greater than or equal to the minimum length, * is null, or the minimum length to check against is null. */ public static boolean validateMinLength(String value, ValidatorAction va, Errors errors, Field field) { if (value == null) { return true; } String sMinLength = field.getVarValue("minlength"); //$NON-NLS-1$ if (sMinLength == null) { return true; } try { int min = Integer.parseInt(sMinLength); if (!GenericValidator.minLength(value, min)) { addError(va, errors, field, Integer.toString(min)); return false; } } catch (Exception e) { addError(va, errors, field); return false; } return true; }
From source file:org.nextframework.validation.validators.MinLengthValidator.java
public void validate(Object bean, Object property, String fieldName, String fieldDisplayName, Annotation annotation, Errors errors, ObjectAnnotationValidator annotationValidator) { if (property != null && !property.toString().trim().equals("")) { MinLength minLength = (MinLength) annotation; int min = minLength.value(); if (!GenericValidator.minLength(property.toString(), min)) { errors.rejectValue(fieldName, "minLenght", "O campo " + fieldDisplayName + " deve ter um tamanho menor ou igual " + min); }// w ww . ja va2 s . co m } }
From source file:org.openmobster.core.common.validation.CoreValidator.java
/** * //from w ww. j a va 2 s. com * @param bean * @param field * @return */ public static boolean minimumLength(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String varValue = field.getVarValue("minimumLength"); return GenericValidator.minLength(value, Integer.parseInt(varValue)); }
From source file:org.sgrp.singer.validator.ArrayFieldChecks.java
/** * Checks if the field's length is greater than or equal to the minimum value. * A <code>Null</code> will be considered an error. * * @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.//from w w w .ja v a 2s.c o m * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. * @return True if stated conditions met. */ public static boolean validateMinLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String[] value = null; if (isStringArray(bean)) { value = (String[]) bean; } else { value = new String[0]; } for (int i = 0; i < value.length; i++) { if (!GenericValidator.isBlankOrNull(value[i])) { try { int min = Integer.parseInt(field.getVarValue("minlength")); if (!GenericValidator.minLength(value[i], min)) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } } return true; }
From source file:org.springmodules.commons.validator.FieldChecks.java
/** * Checks if the field's length is greater than or equal to the minimum * value. A <code>Null</code> will be considered an error. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed./*from ww w.j a v a 2 s .c o m*/ * @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 stated conditions met. */ public static boolean validateMinLength(Object bean, ValidatorAction va, Field field, Errors errors) { String value = extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { try { int min = Integer.parseInt(field.getVarValue("minlength")); if (!GenericValidator.minLength(value, min)) { rejectValue(errors, field, va); return false; } } catch (Exception e) { rejectValue(errors, field, va); return false; } } return true; }
From source file:org.springmodules.validation.commons.FieldChecks.java
/** * Checks if the field's length is greater than or equal to the minimum * value. A <code>Null</code> will be considered an error. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed.//ww w . j a v a 2 s . com * @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 stated conditions met. */ public static boolean validateMinLength(Object bean, ValidatorAction va, Field field, Errors errors) { String value = FieldChecks.extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { try { int min = Integer.parseInt(field.getVarValue("minlength")); if (!GenericValidator.minLength(value, min)) { FieldChecks.rejectValue(errors, field, va); return false; } } catch (Exception e) { FieldChecks.rejectValue(errors, field, va); return false; } } return true; }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.EctValidation.java
public boolean minLength(int iMin, String inputValue) { boolean validation = true; org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator(); if (iMin != 0) { if (!GenericValidator.minLength(inputValue, iMin)) { validation = false;//from w ww. j a va 2 s .c o m } } return validation; }