Example usage for org.apache.commons.validator GenericValidator isEmail

List of usage examples for org.apache.commons.validator GenericValidator isEmail

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isEmail.

Prototype

public static boolean isEmail(String value) 

Source Link

Document

Checks if a field has a valid e-mail address.

Usage

From source file:org.asqatasun.rules.elementchecker.lang.LangChecker.java

/**
 * /* w  w w  .  j  a va2s .c  o m*/
 * @param extractedText
 * @return 
 */
protected boolean isTextTestable(String extractedText) {
    if (StringUtils.isBlank(extractedText)) {
        return false;
    }
    String textToTest = StringUtils.trim(extractedText);
    Matcher m = nonAlphanumericPattern.matcher(textToTest);
    return !m.matches() && !GenericValidator.isEmail(textToTest) && !GenericValidator.isUrl(textToTest);
}

From source file:org.broadleafcommerce.core.web.checkout.validator.CheckoutFormValidator.java

public void validate(Object obj, Errors errors) {
    CheckoutForm checkoutForm = (CheckoutForm) obj;
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.addressLine1", "addressLine1.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.phonePrimary", "phone.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.city", "city.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postalCode", "postalCode.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "lastName.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.addressLine1", "addressLine1.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.city", "city.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.postalCode", "postalCode.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shippingAddress.lastName", "lastName.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardNumber", "creditCardNumber.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardCvvCode", "creditCardCvvCode.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpMonth", "creditCardExpMonth.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "creditCardExpYear", "creditCardExpYear.required");

    if (!errors.hasErrors()) {
        if (!GenericValidator.isEmail(checkoutForm.getEmailAddress())) {
            errors.rejectValue("emailAddress", "emailAddress.invalid", null, null);
        }/*  w  w  w .j  a  v a  2 s.  co  m*/
    }
}

From source file:org.broadleafcommerce.core.web.controller.account.validator.UpdateAccountValidator.java

public void validate(UpdateAccountForm form, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");

    if (!errors.hasErrors()) {

        //is this a valid email address?
        if (!GenericValidator.isEmail(form.getEmailAddress())) {
            errors.rejectValue("emailAddress", "emailAddress.invalid");
        }//  www  .ja v  a 2  s.  c o m

        //check email address to see if it is already in use by another customer
        Customer customerMatchingNewEmail = customerService.readCustomerByEmail(form.getEmailAddress());

        if (customerMatchingNewEmail != null
                && !CustomerState.getCustomer().getId().equals(customerMatchingNewEmail.getId())) {
            //customer found with new email entered, and it is not the current customer
            errors.rejectValue("emailAddress", "emailAddress.used");
        }

    }

}

From source file:org.broadleafcommerce.profile.core.service.validator.RegistrationValidator.java

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();/*from w w w.  j  a  v  a2 s .  c  o  m*/

    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);
        }
    }
}

From source file:org.broadleafcommerce.profile.web.controller.validator.RegisterCustomerValidator.java

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 {//from   w  ww. j av a2  s.co m
            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);
        }
    }
}

From source file:org.eclipse.riena.ui.ridgets.validation.ValidEmailAddress.java

public IStatus validate(final Object value) {
    if (value == null) {
        return ValidationRuleStatus.ok();
    }//www. j  av a 2  s  .  co  m
    // note: null instanceof String == false
    if (!(value instanceof String)) {
        throw new ValidationFailure(getClass().getSimpleName() + " can only validate objects of type " //$NON-NLS-1$
                + String.class.getName());
    }
    final String toBeChecked = (String) value;
    if (toBeChecked.length() == 0 || GenericValidator.isEmail(toBeChecked)) {
        return ValidationRuleStatus.ok();
    }
    final String message = NLS.bind(Messages.ValidEmailAddress_error_notValid, toBeChecked);
    return ValidationRuleStatus.error(false, message);
}

From source file:org.megatome.frame2.validator.CommonsFieldValidator.java

/**
 * Validate an email address. Null values pass validation, as this allows
 * them to be optional.//from w  w w .  j ava2  s . c  o m
 * 
 * @param value
 *            The value to validate as an email address.
 * @param va
 *            The validator action
 * @param errors
 *            Errors object to populate
 * @param field
 *            The field to validate
 * @return True if the email address passes validation, or is null.
 */
public static boolean validateEmail(String value, ValidatorAction va, Errors errors, Field field) {
    // If value is null, then don't validate email. This allows the email
    // field to be optional on the input.
    if (value == null) {
        return true;
    }
    if (!GenericValidator.isEmail(value)) {
        addError(va, errors, field);
        return false;
    }

    return true;
}

From source file:org.mifos.customers.personnel.struts.actionforms.PersonActionForm.java

private void validateEmail(ActionErrors errors) {
    if (StringUtils.isNotBlank(emailId) && !GenericValidator.isEmail(emailId)) {
        errors.add(PersonnelConstants.ERROR_VALID_EMAIL,
                new ActionMessage(PersonnelConstants.ERROR_VALID_EMAIL));
    }/*from   w w  w  .ja  v  a  2  s  . c  om*/
}

From source file:org.nextframework.validation.validators.EmailValidator.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("")) {
        if (!GenericValidator.isEmail(property.toString())) {
            errors.rejectValue(fieldName, "email", "O campo " + fieldDisplayName + " deve ser um email");
        }/* ww  w  .  ja  v a  2 s.co  m*/
    }
}

From source file:org.pentaho.di.trans.steps.mailvalidator.MailValidation.java

public static boolean isRegExValid(String emailAdress) {
    return GenericValidator.isEmail(emailAdress);
}