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

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

Introduction

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

Prototype

public boolean isValid(String email) 

Source Link

Document

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

Usage

From source file:business.Klant.java

public void setEmail(String email) {
    EmailValidator emailValidator = EmailValidator.getInstance();
    Scanner input = new Scanner(System.in);

    while (emailValidator.isValid(email) == false) {
        System.out.println("Incorrecte email. Voer uw emailadres opnieuw in");
        email = input.next();// w  w  w. j  av a 2s. c om
    }

    this.email = email;
}

From source file:facade.Controller.java

public void updateKlant() {
    LOGGER.debug("updateKlant() ");
    EmailValidator emailVal = EmailValidator.getInstance();
    view1.clearStatusText();/*from  ww  w  .  j a  v a2s  . com*/
    try {
        if (!emailVal.isValid(view1.getEmail())) {
            view1.falseEmail();
            return;
        }
        leesSchermKlant();
        model.updateKlant(klant);
        nepAppArray = model.getToDisplay();

    } catch (SQLException ex) {
        System.out.println("Nog op te lossen");
    }
}

From source file:facade.Controller.java

public void maakKlant() {
    LOGGER.debug("maakkKlant()");
    EmailValidator emailVal = EmailValidator.getInstance();
    view1.clearStatusText();/*w w w. jav a  2 s  .c o  m*/
    try {
        if (!emailVal.isValid(view1.getEmail())) {
            view1.falseEmail();
            return;
        }
        klant.setKlantID(view1.getKlantID());
        klant.setAchternaam(view1.getKlantAchternaam());
        klant.setEmail(view1.getEmail());
        klant.setVoornaam(view1.getKlantVoornaam());
        klant.setTussenvoegsel(view1.getTussenvoegsel());
        klant = model.createKlant(klant);
        nepAppArray = model.getToDisplay(); // nepapparray[0] is nu kopie
        // van klant niet klant
        // zelf!
    } catch (SQLException e) {
        LOGGER.error("oplossen nog maaklant " + e);
    }
}

From source file:facturas.Facture.java

private void jButtonPrecioTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPrecioTotalActionPerformed
    /*Inroducimos un sonido para que se reproduzca a la hora de realizar 
    la accin del botn.*//*from  w w  w  . ja  va 2 s .  c o  m*/
    try {
        Player player = new Player(getClass().getResourceAsStream("/sounds/BubblePo.mp3"));
        player.play();
        player.close();
    } catch (Exception e) {
        System.out.println("Error al reproducir el audio");
    }
    /*Realizamos las distintas operaciones para averiguar el coste total de 
    los productos con su respectivo importe del iva.*/
    final double IVA = 0.21;

    float price = Float.valueOf(jTextFieldPrice.getText());
    int units = Integer.valueOf(jTextFieldUnits.getText());
    float iva = (float) (price * units * IVA);
    NumberFormat ivaFormat = NumberFormat.getCurrencyInstance();
    jTextFieldIva.setText(String.valueOf(ivaFormat.format(iva)));
    float total = ((price * units) + iva);
    NumberFormat amountFormat = NumberFormat.getCurrencyInstance();
    jTextFieldTotal.setText(String.valueOf(amountFormat.format(total)));

    float price1 = Float.valueOf(jTextFieldPrice1.getText());
    int units1 = Integer.valueOf(jTextFieldUnits1.getText());
    float iva1 = (float) (price1 * units1 * IVA);
    NumberFormat ivaFormat1 = NumberFormat.getCurrencyInstance();
    jTextFieldIva1.setText(String.valueOf(ivaFormat1.format(iva1)));
    float total1 = (price1 * units1) + iva1;
    NumberFormat amountFormat1 = NumberFormat.getCurrencyInstance();
    jTextFieldTotal1.setText(String.valueOf(amountFormat1.format(total1)));

    float price2 = Float.valueOf(jTextFieldPrice2.getText());
    int units2 = Integer.valueOf(jTextFieldUnits2.getText());
    float iva2 = (float) (price2 * units2 * IVA);
    NumberFormat ivaFormat2 = NumberFormat.getCurrencyInstance();
    jTextFieldIva2.setText(String.valueOf(ivaFormat2.format(iva2)));
    float total2 = (price2 * units2) + iva2;
    NumberFormat amountFormat2 = NumberFormat.getCurrencyInstance();
    jTextFieldTotal2.setText(String.valueOf(amountFormat2.format(total2)));

    float price3 = Float.valueOf(jTextFieldPrice3.getText());
    int units3 = Integer.valueOf(jTextFieldUnits3.getText());
    float iva3 = (float) (price3 * units3 * IVA);
    NumberFormat ivaFormat3 = NumberFormat.getCurrencyInstance();
    jTextFieldIva3.setText(String.valueOf(ivaFormat3.format(iva3)));
    float total3 = (price3 * units3) + iva3;
    NumberFormat amountFormat3 = NumberFormat.getCurrencyInstance();
    jTextFieldTotal3.setText(String.valueOf(amountFormat3.format(total3)));

    //Con esto tenemos la suma total de todos los precios.
    float totalEuros = total + total1 + total2 + total3;
    NumberFormat totalFormat = NumberFormat.getCurrencyInstance();
    jTextFieldTotalPrice.setText(String.valueOf(totalFormat.format(totalEuros)));

    EmailValidator emailValidator = EmailValidator.getInstance();
    boolean emailValid = emailValidator.isValid(jTextFieldEmail.getText());
    String mensaje = emailValid ? "Email vlido" : "Email no vlido";
    System.out.println(mensaje);
}

From source file:net.malariagen.alfresco.action.CustomMailAction.java

/**
 * Return true if address has valid format
 * /*from  w ww  .jav a2s. c o  m*/
 * @param address
 *            String
 * @return boolean
 */
private boolean validateAddress(String address) {
    boolean result = false;

    // Validate the email, allowing for local email addresses
    EmailValidator emailValidator = EmailValidator.getInstance(true);
    if (!validateAddresses || emailValidator.isValid(address)) {
        result = true;
    } else {
        logger.error("Failed to send email to '" + address + "' as the address is incorrectly formatted");
    }

    return result;
}

From source file:net.malariagen.alfresco.action.CustomMailAction.java

@SuppressWarnings("unchecked")
private Collection<Pair<String, Locale>> getRecipients(Action ruleAction) {
    Map<String, Pair<String, Locale>> recipients = new HashMap<String, Pair<String, Locale>>();

    // set recipient
    String to = (String) ruleAction.getParameterValue(PARAM_TO);
    if (to != null && to.length() != 0) {
        Locale locale = null;/*from   ww  w .  j av  a2 s.com*/
        if (personExists(to)) {
            locale = getLocaleForUser(to);
        }
        recipients.put(to, new Pair<String, Locale>(to, locale));
    } else {
        // see if multiple recipients have been supplied - as a list of
        // authorities
        Serializable authoritiesValue = ruleAction.getParameterValue(PARAM_TO_MANY);
        List<String> authorities = null;
        if (authoritiesValue != null) {
            if (authoritiesValue instanceof String) {
                authorities = new ArrayList<String>(1);
                authorities.add((String) authoritiesValue);
            } else {
                authorities = (List<String>) authoritiesValue;
            }
        }

        if (authorities != null && authorities.size() != 0) {
            for (String authority : authorities) {
                AuthorityType authType = AuthorityType.getAuthorityType(authority);
                if (authType.equals(AuthorityType.USER)) {
                    // Formerly, this code checked personExists(auth) but we
                    // now support emailing addresses who are not yet
                    // Alfresco users.
                    // Check the user name to be a valid email and we don't
                    // need to log an error in this case
                    // ALF-19231
                    // Validate the email, allowing for local email
                    // addresses
                    if ((authority != null) && (authority.length() != 0)
                            && (!recipients.containsKey(authority))) {
                        if (personExists(authority)) {
                            if (isControlledActivity(ruleAction, authority)) {
                                continue;
                            }
                            String address = getPersonEmail(authority);
                            if (address != null && address.length() != 0 && validateAddress(address)) {
                                Locale locale = getLocaleForUser(authority);
                                recipients.put(authority, new Pair<String, Locale>(address, locale));
                            } else {
                                EmailValidator emailValidator = EmailValidator.getInstance(true);
                                if (validateAddresses && emailValidator.isValid(authority)) {
                                    Locale locale = getLocaleForUser(authority);
                                    recipients.put(authority, new Pair<String, Locale>(authority, locale));
                                }
                            }
                        } else {
                            recipients.put(authority, new Pair<String, Locale>(authority, null));
                        }
                    }
                } else if (authType.equals(AuthorityType.GROUP) || authType.equals(AuthorityType.EVERYONE)) {
                    // Notify all members of the group
                    Set<String> users;
                    if (authType.equals(AuthorityType.GROUP)) {
                        users = authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
                    } else {
                        users = authorityService.getAllAuthorities(AuthorityType.USER);
                    }

                    for (String userAuth : users) {
                        if (recipients.containsKey(userAuth)) {
                            continue;
                        }
                        if (personExists(userAuth)) {
                            if (isControlledActivity(ruleAction, userAuth)) {
                                continue;
                            }
                            // Check the user name to be a valid email and
                            // we don't need to log an error in this case
                            // ALF-19231
                            // Validate the email, allowing for local email
                            // addresses
                            String address = getPersonEmail(userAuth);
                            if (address != null && address.length() != 0 && validateAddress(address)) {
                                Locale locale = getLocaleForUser(userAuth);
                                recipients.put(userAuth, new Pair<String, Locale>(address, locale));
                            } else {
                                EmailValidator emailValidator = EmailValidator.getInstance(true);
                                if (validateAddresses && emailValidator.isValid(userAuth)) {
                                    if (userAuth != null && userAuth.length() != 0) {
                                        Locale locale = getLocaleForUser(userAuth);
                                        recipients.put(userAuth, new Pair<String, Locale>(userAuth, locale));
                                    }
                                }
                            }
                        } else {
                            recipients.put(userAuth, new Pair<String, Locale>(authority, null));
                        }
                    }
                }
            }
            if (recipients.size() <= 0) {
                // All recipients were invalid
                throw new MailPreparationException("All recipients for the mail action were invalid");
            }
        } else {
            // No recipients have been specified
            throw new MailPreparationException("No recipient has been specified for the mail action");
        }
    }
    return recipients.values();
}

From source file:com.osparking.attendant.AttListForm.java

private boolean validateEmail(String email) {
    //Create InternetAddress object and validated the email address.
    final EmailValidator emailValidator = EmailValidator.getInstance();

    return emailValidator.isValid(email);
}

From source file:edu.ksu.cs.a4vm.bse.Util.java

public static boolean isEmailValid(String email) {
    org.apache.commons.validator.routines.EmailValidator emv = org.apache.commons.validator.routines.EmailValidator
            .getInstance();//from  w w w. java  2 s .co  m
    if (email.length() == 0 || emv.isValid(email)) {
        return true;
    } else
        return false;
}

From source file:nl.rkk.marktplaats.validation.EmailValidation.java

@Override
public boolean validate() {
    EmailValidator val = EmailValidator.getInstance();
    if (val.isValid(this.param)) {
        return true;
    } else {/*from  w  w  w.j a  v a2 s .c o m*/
        this.addError("E-mail address is invalid.");
        return false;
    }
}

From source file:org.alfresco.repo.action.executer.MailActionExecuter.java

@SuppressWarnings("unchecked")
private Collection<Pair<String, Locale>> getRecipients(Action ruleAction) {
    Map<String, Pair<String, Locale>> recipients = new HashMap<String, Pair<String, Locale>>();

    // set recipient
    String to = (String) ruleAction.getParameterValue(PARAM_TO);
    if (to != null && to.length() != 0) {
        Locale locale = null;//from ww  w  .j a v  a  2  s .c o m
        if (personExists(to)) {
            locale = getLocaleForUser(to);
        }
        recipients.put(to, new Pair<String, Locale>(to, locale));
    } else {
        // see if multiple recipients have been supplied - as a list of authorities
        Serializable authoritiesValue = ruleAction.getParameterValue(PARAM_TO_MANY);
        List<String> authorities = null;
        if (authoritiesValue != null) {
            if (authoritiesValue instanceof String) {
                authorities = new ArrayList<String>(1);
                authorities.add((String) authoritiesValue);
            } else {
                authorities = (List<String>) authoritiesValue;
            }
        }

        if (authorities != null && authorities.size() != 0) {
            for (String authority : authorities) {
                AuthorityType authType = AuthorityType.getAuthorityType(authority);
                if (authType.equals(AuthorityType.USER)) {
                    // Formerly, this code checked personExists(auth) but we now support emailing addresses who are not yet Alfresco users.
                    // Check the user name to be a valid email and we don't need to log an error in this case
                    // ALF-19231
                    // Validate the email, allowing for local email addresses
                    if ((authority != null) && (authority.length() != 0)
                            && (!recipients.containsKey(authority))) {
                        if (personExists(authority)) {
                            String address = getPersonEmail(authority);
                            if (address != null && address.length() != 0 && validateAddress(address)) {
                                Locale locale = getLocaleForUser(authority);
                                recipients.put(authority, new Pair<String, Locale>(address, locale));
                            } else {
                                EmailValidator emailValidator = EmailValidator.getInstance(true);
                                if (validateAddresses && emailValidator.isValid(authority)) {
                                    Locale locale = getLocaleForUser(authority);
                                    recipients.put(authority, new Pair<String, Locale>(authority, locale));
                                }
                            }
                        } else {
                            recipients.put(authority, new Pair<String, Locale>(authority, null));
                        }
                    }
                } else if (authType.equals(AuthorityType.GROUP) || authType.equals(AuthorityType.EVERYONE)) {
                    // Notify all members of the group
                    Set<String> users;
                    if (authType.equals(AuthorityType.GROUP)) {
                        users = authorityService.getContainedAuthorities(AuthorityType.USER, authority, false);
                    } else {
                        users = authorityService.getAllAuthorities(AuthorityType.USER);
                    }

                    for (String userAuth : users) {
                        if (recipients.containsKey(userAuth)) {
                            continue;
                        }
                        if (personExists(userAuth)) {
                            // Check the user name to be a valid email and we don't need to log an error in this case
                            // ALF-19231
                            // Validate the email, allowing for local email addresses
                            String address = getPersonEmail(userAuth);
                            if (address != null && address.length() != 0 && validateAddress(address)) {
                                Locale locale = getLocaleForUser(userAuth);
                                recipients.put(userAuth, new Pair<String, Locale>(address, locale));
                            } else {
                                EmailValidator emailValidator = EmailValidator.getInstance(true);
                                if (validateAddresses && emailValidator.isValid(userAuth)) {
                                    if (userAuth != null && userAuth.length() != 0) {
                                        Locale locale = getLocaleForUser(userAuth);
                                        recipients.put(userAuth, new Pair<String, Locale>(userAuth, locale));
                                    }
                                }
                            }
                        } else {
                            recipients.put(userAuth, new Pair<String, Locale>(authority, null));
                        }
                    }
                }
            }
            if (recipients.size() <= 0) {
                // All recipients were invalid
                throw new MailPreparationException("All recipients for the mail action were invalid");
            }
        } else {
            // No recipients have been specified
            throw new MailPreparationException("No recipient has been specified for the mail action");
        }
    }
    return recipients.values();
}