List of usage examples for org.apache.commons.validator EmailValidator getInstance
public static EmailValidator getInstance()
From source file:com.seajas.search.codex.validator.IdentityValidator.java
/** * Validate the given command object./*from w w w . ja v a2 s . c o m*/ * * @param command * @param errors */ @Override public void validate(final Object command, final Errors errors) { IdentityCommand identity = (IdentityCommand) command; if ("add".equals(identity.getAction()) || "edit".equals(identity.getAction())) { if (StringUtils.isEmpty(identity.getName())) errors.rejectValue("name", "identities.error.name.empty"); if (StringUtils.isEmpty(identity.getNotifierEmail())) errors.rejectValue("notifierEmail", "identities.error.notifier.email.empty"); else if (!EmailValidator.getInstance().isValid(identity.getNotifierEmail())) errors.rejectValue("notifierEmail", "identities.error.notifier.email.invalid"); // Everything else may be either empty, or null } if ("add-account".equals(identity.getAccountAction()) || "edit-account".equals(identity.getAccountAction())) { if (StringUtils.isEmpty(identity.getUsername())) errors.rejectValue("username", "identities.account.error.username.empty"); if (StringUtils.isEmpty(identity.getPassword())) errors.rejectValue("password", "identities.account.error.password.empty"); if (StringUtils.isEmpty(identity.getType())) errors.rejectValue("type", "identities.account.error.type.empty"); } }
From source file:com.konakart.actions.SubscribeNewsletterSubmitAction.java
public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try {//from ww w.ja v a 2 s. c om int custId; KKAppEng kkAppEng = this.getKKAppEng(request, response); custId = this.loggedIn(request, response, kkAppEng, null); // Ensure we are using the correct protocol. Redirect if not. String redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */false); if (redirForward != null) { setupResponseForSSLRedirect(response, redirForward); return null; } EmailValidator validator = EmailValidator.getInstance(); if (!validator.isValid(emailAddr)) { msg = "Enter a valid email address"; error = true; return SUCCESS; } NotificationOptions options = new NotificationOptions(); options.setEmailAddr(emailAddr); options.setNewsletter(true); options.setAllProducts(false); options.setCustomerId(custId); if (custId > 0) { options.setSessionId(kkAppEng.getSessionId()); } try { kkAppEng.getEng().addCustomerNotifications(options); } catch (Exception e) { String userExists = "KKUserExistsException"; if ((e.getCause() != null && e.getCause().getClass().getName().indexOf(userExists) > -1) || (e.getMessage() != null && e.getMessage().indexOf(userExists) > -1)) { msg = "Sign in to register"; } error = true; return SUCCESS; } msg = "Registration was successful"; return SUCCESS; } catch (Exception e) { return super.handleException(request, e); } }
From source file:gov.nih.nci.cananolab.restful.security.RegisterUserBO.java
protected List<String> validateInput(String firstName, String lastName, String email, String phone, String organization, String fax, String comment) { List<String> errors = new ArrayList<String>(); if (firstName == null || !InputValidationUtil.isAlphabetic(firstName)) errors.add(PropertyUtil.getProperty("application", "firstName.invalid")); if (lastName == null || !InputValidationUtil.isAlphabetic(lastName)) errors.add(PropertyUtil.getProperty("application", "lastName.invalid")); EmailValidator emailValidator = EmailValidator.getInstance(); if (email == null || !emailValidator.isValid(email)) errors.add("Email is invalid"); if (phone == null || !InputValidationUtil.isPhoneValid(phone)) errors.add(PropertyUtil.getProperty("application", "phone.invalid")); if (fax == null || !InputValidationUtil.isPhoneValid(fax)) errors.add(PropertyUtil.getProperty("application", "fax.invalid")); if (organization == null || organization.length() == 0) errors.add(PropertyUtil.getProperty("application", "organization.name.invalid")); if (comment != null && comment.length() > 4000) errors.add("Comment exceeded the max length of 4000"); return errors; }
From source file:de.knurt.fam.template.controller.letter.EMailLetterAdapter.java
public EMailLetterAdapter(String from, String to, String subject, String msg) { this.from = from; this.to = to; this.subject = subject; this.msg = msg; if (this.from == null || !EmailValidator.getInstance().isValid(this.from)) { this.from = UserMailSender.getInstance().getFromMail(); }/* w w w. j a v a 2 s .co m*/ if (this.subject == null || this.subject.trim().isEmpty()) { this.subject = "[FAM] no subject"; // INTLANG } if (this.msg == null || this.msg.trim().isEmpty()) { this.msg = "[FAM] no message"; // INTLANG } }
From source file:com.adsapient.gui.forms.PassReminderForm.java
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if (action.equals("init")) { return null; }/* ww w .j av a 2 s . co m*/ String emailLower = email.toLowerCase(); if (email.length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.emailrequired")); return errors; } if (email != emailLower) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.emailrequiredforcase")); return errors; } EmailValidator ev = EmailValidator.getInstance(); if (!ev.isValid(email)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.wrongemail")); return errors; } return errors; }
From source file:formatMessage.VerifyInputScanner.java
/** * Ga naar https://commons.apache.org/proper/commons-validator/download_validator.cgi * download de bin file/*www . j a v a 2 s .c o m*/ * Ga naar libraries in netbeans rechtermuisknop workshop1 properties * Druk op libraries * add library * create * dan add the file commons-validator-1.5.0 aan de classpath * * @return */ public static String verifyEmail() { Scanner input = new Scanner(System.in); while (true) { try { String verified = input.next(); EmailValidator emailVal = EmailValidator.getInstance(); if (emailVal.isValid(verified)) { return verified; } } catch (InputMismatchException e) { System.out.println("Geen juiste invoer probeer opnieuw"); } } }
From source file:de.knurt.fam.template.controller.letter.EMailLetterAdapter.java
protected EMailLetterAdapter(TemplateResource tr) { // set from/* w w w . j a va 2 s. c om*/ from = tr.getRequest().getParameter("email_from"); if (from == null || !EmailValidator.getInstance().isValid(from)) { from = UserMailSender.getInstance().getFromMail(); } // to to = tr.getRequest().getParameter("email_recipient"); // subject subject = tr.getRequest().getParameter("email_subject"); if (subject == null || subject.trim().isEmpty()) { subject = "[FAM] no subject"; // INTLANG } // message msg = tr.getRequest().getParameter("email_message"); if (msg == null || msg.trim().isEmpty()) { msg = "[FAM] no message"; // INTLANG } }
From source file:de.knurt.fam.core.util.mvc.validator.JmValidationUtils.java
/** * Reject the given field with the given error code (and default message) if * the value is not a valie email address * /*from w w w . java2s .c o m*/ * @param errors * the Errors instance to register errors on * @param field * the field name to check * @param errorCode * error code, interpretable as message key * @param errorArgs * the error arguments, for argument binding via MessageFormat * (can be null) * @param defaultMessage * fallback default message */ public static void rejectIfNotEmail(Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) { Object value = errors.getFieldValue(field); if (value == null || EmailValidator.getInstance().isValid(value.toString()) == false) { errors.rejectValue(field, errorCode, errorArgs, defaultMessage); } }
From source file:com.adsapient.gui.forms.ContactForm.java
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ValidationService validator = new ValidationService(); ActionErrors errors = new ActionErrors(); String errorMsg = ""; if (action.equals("init")) { return null; }// w ww . j a va 2s. c o m if (name.trim().length() == 0) { errors.add("errors.required", new ActionMessage("error.name.required")); return errors; } if (!validator.isAlphanumeric(name, "_., /:@&")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphanum", I18nService.fetch("form.name", request))); return errors; } String emailLower = email.toLowerCase(); if (email.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.email.required")); return errors; } if (email != emailLower) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.email.requiredforcase")); return errors; } EmailValidator ev = EmailValidator.getInstance(); if (!ev.isValid(email)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.wrongemail")); return errors; } if (message.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.message.required")); return errors; } if (!validator.isAlphanumeric(message, "_., /:@&")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphanum", I18nService.fetch("message", request))); return errors; } if (message.trim().length() > 500) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("", "Message should not exceed 500 charecters")); return errors; } return errors; }
From source file:de.knurt.fam.template.controller.letter.EMailLetterAdapter.java
protected boolean isValid() { return this.to != null && EmailValidator.getInstance().isValid(to); }