public void validate(Customer customer, String password, String passwordConfirm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace( errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (errors.hasErrors()) { if (!passwordConfirm.equals(password)) { errors.rejectValue("passwordConfirm", "invalid"); } if (!customer.getFirstName().matches(validNameRegex)) { errors.rejectValue("firstName", "firstName.invalid", null, null); } if (!customer.getLastName().matches(validNameRegex)) { errors.rejectValue("lastName", "lastName.invalid", null, null); } if (!customer.getPassword().matches(validPasswordRegex)) { errors.rejectValue("password", "password.invalid", null, null); } if (!password.equals(passwordConfirm)) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(customer.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } }
public void validate(Errors errors) { if (StringUtils.isBlank(getUser().getCsmUser().getLoginName())) { errors.rejectValue("user.csmUser.loginName", "error.user.name.not.specified"); } else { User existing = authorizationManager.getUser(getUser().getCsmUser().getLoginName()); boolean existingMismatch = existing != null && !existing.getUserId().equals(getUser().getCsmUser().getUserId()); if (!lookUpBoundUser && ((isNewUser() && existing != null) || existingMismatch)) { errors.rejectValue("user.csmUser.loginName", "error.user.name.already.exists"); } } if (StringUtils.isBlank(getUser().getCsmUser().getFirstName())) { errors.rejectValue("user.csmUser.firstName", "error.user.firstName.not.specified"); } if (StringUtils.isBlank(getUser().getCsmUser().getLastName())) { errors.rejectValue("user.csmUser.lastName", "error.user.lastName.not.specified"); } if (!GenericValidator.isEmail(getUser().getCsmUser().getEmailId())) { errors.rejectValue("user.csmUser.emailId", "error.user.email.invalid"); } if (isNewUser() && getUsesLocalPasswords() && (StringUtils.isBlank(getPassword()))) { errors.rejectValue("password", "error.user.password.not.specified"); } if (getPassword() != null || getRePassword() != null) { if (!ComparisonUtils.nullSafeEquals(getPassword(), getRePassword())) { errors.rejectValue("rePassword", "error.user.repassword.does.not.match.password"); } } }
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { String value = null; value = getValueAsString(source, propertyName); if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME)); return false; } else { return true; } }
public void validate(Object obj, Errors errors, boolean useEmailForUsername) { RegisterCustomerForm form = (RegisterCustomerForm) obj; Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername()); if (customerFromDb != null) { if (useEmailForUsername) { errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null); } else { errors.rejectValue("customer.username", "username.used", null, null); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace( errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (!errors.hasErrors()) { if (!form.getPassword().matches(getValidatePasswordExpression())) { errors.rejectValue("password", "password.invalid", null, null); } if (!form.getPassword().equals(form.getPasswordConfirm())) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) { errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null); } } }