Example usage for org.apache.commons.validator.routines EmailValidator getInstance

List of usage examples for org.apache.commons.validator.routines EmailValidator getInstance

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines EmailValidator getInstance.

Prototype

public static EmailValidator getInstance() 

Source Link

Document

Returns the Singleton instance of this validator.

Usage

From source file:rems.Global.java

private static boolean isEmailValid(String email, int lovID) {
    if (email == null || "".equals(email)) {
        return false;
    }//  ww  w  .ja v  a 2  s.c om
    email = email.trim();
    EmailValidator ev = EmailValidator.getInstance();
    boolean isEmailValid = ev.isValid(email);
    if (isEmailValid == false) {
        Global.createSysLovsPssblVals1(email, lovID);
    }
    return isEmailValid;
}

From source file:servlets.registrationServlet.java

private String validateSigner(String signerName, String signerEmail) {
    if (signerName == null || signerName.isEmpty()) {
        return "Please specify the signer name.";
    }//ww  w.j  a  v a 2 s . c o  m

    if (signerEmail == null || signerEmail.isEmpty()) {
        return "Please specify the signer email.";
    }

    if (!EmailValidator.getInstance().isValid(signerEmail)) {
        return "Please specify a valid email address.";
    }

    return "";
}

From source file:servlets.registrationServlet.java

private String validateUser(String userName, String password, String confirmPassword, String emailId) {
    if (userName == null || userName.length() == 0) {
        return "Please specify a user name.";
    }/*w  w w. ja v  a 2s .c om*/

    if (password == null || password.length() == 0) {
        return "Please specify a password.";
    }

    if (confirmPassword == null || confirmPassword.length() == 0) {
        return "Please confirm password.";
    }

    if (!password.equals(confirmPassword)) {
        return "Passwords do not match.";
    }

    if (emailId == null || emailId.length() == 0) {
        return "Please specify an email address.";
    }

    if (!EmailValidator.getInstance().isValid(emailId)) {
        return "Please specify a valid email address.";
    }

    return "";
}

From source file:Tim.MarkovChains.java

public MarkovChains() {
    this.emailValidator = EmailValidator.getInstance();
}

From source file:ua.its.slot7.camailtask.model.MailTask.java

/**
 * Email address validation according to RFC 822 standards
 *
 * @param emailToVerify Email to verify. Can't be null, can't be empty.
 */// ww w  . j a v  a 2  s  .  c  o  m
public boolean emailVerify(String emailToVerify) {
    if (emailToVerify == null) {
        throw new NullPointerException("Arguments can't be null.");
    }
    if (emailToVerify.length() == 0) {
        throw new IllegalArgumentException("Arguments can't be empty.");
    }

    EmailValidator validator = EmailValidator.getInstance();
    return validator.isValid(emailToVerify);
}

From source file:uk.gov.gds.locate.api.frontend.validation.ValidationCreateUserRequest.java

public static List<String> validateRequest(CreateUserRequest request) {
    List<String> errors = new ArrayList<String>();

    if (Strings.isNullOrEmpty(request.getAppName()) || request.getAppName().length() > MAX_LENGTH) {
        errors.add(APP_NAME_ERROR);//from   ww  w.  j  a  v  a  2  s .  c om
    }

    if (Strings.isNullOrEmpty(request.getName()) || request.getName().length() > MAX_LENGTH) {
        errors.add(NAME_ERROR);
    }

    if (!EmailValidator.getInstance().isValid(request.getEmail()) || !request.getEmail().endsWith(".gov.uk")
            || request.getEmail().length() > MAX_LENGTH) {
        errors.add(EMAIL_ERROR);
    }

    if (Strings.isNullOrEmpty(request.getOrganisation()) || request.getOrganisation().length() > MAX_LENGTH) {
        errors.add(ORGANISATION_ERROR);
    }

    if (Strings.isNullOrEmpty(request.getPSMA()) || request.getPSMA().length() > MAX_LENGTH) {
        errors.add(PSMA_ERROR);
    }

    return errors;
}

From source file:uk.org.rbc1b.roms.controller.volunteer.update.VolunteerUpdateController.java

private void assertVolunteerInformationIsValid(Volunteer volunteer) {
    if (volunteer.getPerson().getBirthDate() == null) {
        throw new UnprocessableEntityRequestException(
                "Volunteer #" + volunteer.getPersonId() + " birth date is not set");
    }/*from  w  ww.  jav a  2 s . c  o m*/
    if (volunteer.getPerson().getEmail() == null) {
        throw new UnprocessableEntityRequestException(
                "Volunteer #" + volunteer.getPersonId() + " email is not set");
    }
    if (!EmailValidator.getInstance().isValid(volunteer.getPerson().getEmail())) {
        throw new UnprocessableEntityRequestException(
                "Volunteer #" + volunteer.getPersonId() + " email is not valid");
    }
}

From source file:validador.main.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    CreditCardValidator comprobar = new CreditCardValidator();
    String numtarjetacredito = jTextFieldtarjetacredito.getText();
    boolean validezcc = comprobar.isValid(numtarjetacredito);
    if (validezcc) {
        jTextField1.setBackground(Color.green);
        jTextField1.setText("correcto");
    } else {/*from  w ww .ja v a2s .  c  o  m*/
        jTextField1.setBackground(Color.red);
        jTextField1.setText("Incorrecto");
    }
    ISBNValidator comprobarlibro = new ISBNValidator();
    String numlibro = jTextFieldcodigolibro.getText();
    boolean validezisbn = comprobarlibro.isValid(numlibro);
    if (validezisbn) {
        jTextField2.setBackground(Color.green);
        jTextField2.setText("correcto");
    } else {
        jTextField2.setBackground(Color.red);
        jTextField2.setText("Incorrecto");
    }
    EmailValidator comprobaremail = EmailValidator.getInstance();
    boolean validezemail = comprobaremail.isValid(jTextFieldemail.getText());
    if (validezemail) {
        jTextField3.setBackground(Color.green);
        jTextField3.setText("correcto");
    } else {
        jTextField3.setBackground(Color.red);
        jTextField3.setText("Incorrecto");
    }

}

From source file:validadores.Validadores.java

private void botonComprobarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonComprobarActionPerformed
    CreditCardValidator comprobarTarjeta = new CreditCardValidator();
    String numTarjeta = campoTarjeta.getText();
    campoValido1.setText((comprobarTarjeta.isValid(numTarjeta) ? "Correcto" : "Incorrecto"));

    ISBNValidator comprobarISBN = new ISBNValidator();
    String codigoISBN = campoISBN.getText();
    campoValido2.setText((comprobarISBN.isValid(codigoISBN) ? "Correcto" : "Incorrecto"));

    String eMail = campoMail.getText();
    EmailValidator comprobarMail = EmailValidator.getInstance();
    campoValido3.setText(comprobarMail.isValid(eMail) ? "Correcto" : "Incorrecto");

    // TODO add your handling code here:
}

From source file:war.controller.UserController.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerNewUser(@ModelAttribute User user, Model model) {
    logger.debug("Inside registerNewUser");

    try {/*w  w w .  j  a va  2s.com*/
        if (user.getUsername() == null || user.getUsername().isEmpty())
            throw (new Exception(ERR_SIGNUP_INVALID_LOGIN));
        if (user.getFirstname() == null || user.getFirstname().isEmpty())
            throw (new Exception(ERR_SIGNUP_INVALID_FIRSTNAME));
        if (user.getLastname() == null || user.getLastname().isEmpty())
            throw (new Exception(ERR_SIGNUP_INVALID_LASTNAME));
        if (user.getEmail() == null || user.getEmail().isEmpty()
                || !(EmailValidator.getInstance().isValid(user.getEmail())))
            throw (new Exception(ERR_SIGNUP_INVALID_EMAIL));
        if (user.getPassword() == null || user.getPassword().length() < 5)
            throw (new Exception(ERR_SIGNUP_INVALID_PASSWORD));
        else {
            // Hash the password using Sha-256 algorithm.
            // (same algorithm as defined for Spring Security in 'appContext-security.xml')
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(user.getPassword().getBytes("UTF-8"));
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < hash.length; i++) {
                String hex = Integer.toHexString(0xff & hash[i]);
                if (hex.length() == 1)
                    hexString.append('0');
                hexString.append(hex);
            }
            user.setPassword(hexString.toString());
        }

        user.setRoles(UserLoginService.ROLE_USER);
        user.setNonLocked(true);
        user.setEnabled(true);

        userDao.save(user);
        return "introduction";
    } catch (Exception e) {
        model.addAttribute("errorMessage", e.getMessage());
        return "register";
    }
}