List of usage examples for org.apache.commons.validator EmailValidator isValid
public boolean isValid(String email)
Checks if a field has a valid e-mail address.
From source file:com.konakart.actions.SubscribeNewsletterSubmitAction.java
public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); try {/*from w w w . j a va 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: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 w w . j a v a2 s . com*/ 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:com.googlecode.osde.internal.ui.wizards.newjsprj.WizardNewGadgetXmlPage.java
/** * Validates user input.//from w w w .j a v a 2 s . c o m * * @return true if the title and gadget spec file names are not empty, and the email is valid */ private boolean validatePage() { String specFilename = specFilenameText.getText().trim(); if (specFilename.length() == 0) { setErrorMessage("Gadget spec file name is empty. Please enter gadget spec file name."); setMessage(null); return false; } String title = titleText.getText().trim(); if (title.length() == 0) { setErrorMessage("Title is empty. Please enter the title."); setMessage(null); return false; } String authorEmail = authorEmailText.getText().trim(); EmailValidator emailValidator = EmailValidator.getInstance(); if (!emailValidator.isValid(authorEmail)) { setErrorMessage("Invalid author email. Please enter a valid email."); setMessage(null); return false; } setErrorMessage(null); setMessage("Click Next to continue."); return true; }
From source file:com.adsapient.gui.forms.EditUserForm.java
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); com.adsapient.shared.service.ValidationService validator = new com.adsapient.shared.service.ValidationService(); if ("init".equalsIgnoreCase(this.action) || "view".equalsIgnoreCase(this.action) || "remove".equalsIgnoreCase(this.action) || "viewProfile".equalsIgnoreCase(this.action)) { return null; }//from w w w . j a v a2 s .c o m if (name.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.namerequired")); return errors; } if (!validator.isAlphabets(name, " _.,")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphabets", I18nService.fetch("form.name", request))); return errors; } if (login.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.loginrequired")); return errors; } if (!validator.isAlphabets(login, " _.,")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphanum", I18nService.fetch("login.username", request))); return errors; } if (password.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.passwordrequired")); return errors; } if (!password.equals(confirmpassword) && (password.length() != 0)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.confirmpassword")); return errors; } String emailLower = email.toLowerCase(); if (email.trim().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:com.adsapient.gui.forms.ProfileEditActionForm.java
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); ValidationService validator = new ValidationService(); if ("init".equalsIgnoreCase(this.action) || "view".equalsIgnoreCase(this.action) || "remove".equalsIgnoreCase(this.action) || "viewProfile".equalsIgnoreCase(this.action) || "resetStatistic".equalsIgnoreCase(this.action)) { return null; }/*from ww w .ja va 2 s.c o m*/ if (name.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.namerequired")); return errors; } if (!validator.isAlphabets(name, " _.,")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphabets", I18nService.fetch("form.name", request))); return errors; } if (profileLogin.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.loginrequired")); return errors; } if (!validator.isAlphanumeric(profileLogin, "_., /:@&")) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("errors.alphanum", I18nService.fetch("login", request))); return errors; } if (profilePassword.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.passwordrequired")); return errors; } if (!profilePassword.equals(confirmpassword) && (profilePassword.length() != 0)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.confirmpassword")); return errors; } if (email.trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.emailrequired")); return errors; } if (email != email.toLowerCase()) { 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; } return errors; }
From source file:cu.uci.coj.restapi.controller.RestUserProfileController.java
private String ValidateUser(User user) { ResourceBundleMessageSource r = new ResourceBundleMessageSource(); r.setBasename("messages_en"); user.setDob(new Date(user.getYear() - 1900, user.getMonth() - 1, user.getDay())); if (user.getNick().length() == 0) return r.getMessage("judge.register.error.nick", null, new Locale("en")); if ((user.getNick().length()) > 15) return r.getMessage("judge.register.error.long25charact", null, new Locale("en")); if (user.getNick().length() < 3) return r.getMessage("judge.register.error.less3charact", null, new Locale("en")); if (user.getName().length() < 1) return r.getMessage("errormsg.7", null, new Locale("en")); if (user.getName().length() > 30) return r.getMessage("errormsg.6", null, new Locale("en")); if (!user.getName().matches("[a-zA-Z\\.\\-\\'\\s]+")) return r.getMessage("errormsg.8", null, new Locale("en")); if (user.getLastname().length() < 1) return r.getMessage("errormsg.10", null, new Locale("en")); if (user.getLastname().length() > 50) return r.getMessage("errormsg.9", null, new Locale("en")); if (!user.getLastname().matches("[a-zA-Z\\.\\-\\'\\s]+")) return r.getMessage("errormsg.11", null, new Locale("en")); // si el correo ha sido cambiado y esta en uso por otra persona en el // COJ/*from ww w . j a v a 2 s.c om*/ if (user.getEmail().length() == 0) return r.getMessage("errormsg.51", null, new Locale("en")); if (!StringUtils.isEmpty(user.getEmail()) && userDAO.bool("email.changed", user.getEmail(), user.getUid()) && userDAO.emailExistUpdate(user.getEmail().trim(), user.getUsername())) return r.getMessage("judge.register.error.emailexist", null, new Locale("en")); EmailValidator emailValidator = EmailValidator.getInstance(); //ver como inyectar este objeto if (!emailValidator.isValid(user.getEmail())) return r.getMessage("judge.register.error.bademail", null, new Locale("en")); if (user.getCountry_id() == 0) return r.getMessage("judge.register.error.country", null, new Locale("en")); if (user.getInstitution_id() == 0) return r.getMessage("judge.register.error.institution", null, new Locale("en")); if (user.getLid() == 0) return r.getMessage("judge.register.error.planguage", null, new Locale("en")); if (user.getLocale() == 0) return r.getMessage("judge.register.error.locale", null, new Locale("en")); if (user.getName().length() == 0) return r.getMessage("judge.register.error.name", null, new Locale("en")); if (user.getGender() == 0) return r.getMessage("judge.register.error.gender", null, new Locale("en")); return "0"; }
From source file:com.patrolpro.beans.SignupClientBean.java
public boolean validateInformation() { boolean isValid = true; FacesContext myContext = FacesContext.getCurrentInstance(); if (contactName == null || contactName.length() < 3) { myContext.addMessage(this.nameErrorLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a your name!")); isValid = false;/* www .j a v a 2s .c o m*/ } if (companyName == null || companyName.length() < 3) { myContext.addMessage(this.companyNameLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a company name!")); isValid = false; } EmailValidator emailValidator = EmailValidator.getInstance(); if (contactEmail == null || contactEmail.length() < 3) { myContext.addMessage(this.contactEmailLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a contact email!")); isValid = false; } else if (!emailValidator.isValid(contactEmail)) { myContext.addMessage(this.contactEmailLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a valid email!")); isValid = false; } if (contactPhone == null || contactPhone.length() < 3) { myContext.addMessage(this.contactPhoneLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a contact phone number!")); isValid = false; } return isValid; }
From source file:gov.nih.nci.cananolab.restful.sample.SampleBO.java
protected List<String> validatePointOfContactInput(SimplePointOfContactBean simplePOC) { List<String> errors = new ArrayList<String>(); if (simplePOC == null) { errors.add("Input point of contact object invalid"); //shouldn't happen return errors; }//from w ww . j av a2 s .com //errors = RestValidator.validate(simplePOC); SimpleOrganizationBean simpleOrg = simplePOC.getOrganization(); if (simpleOrg != null) { String orgName = simpleOrg.getName(); if (orgName == null || !InputValidationUtil.isTextFieldWhiteList(orgName)) errors.add(PropertyUtil.getProperty("sample", "organization.name.invalid")); } else errors.add("Organization Name is a required field"); SimpleAddressBean addrBean = simplePOC.getAddress(); if (addrBean != null) { String val = addrBean.getLine1(); if (val != null && val.length() > 0 && !InputValidationUtil.isTextFieldWhiteList(val)) errors.add(PropertyUtil.getProperty("sample", "organization.address1.invalid")); val = addrBean.getLine2(); if (val != null && val.length() > 0 && !InputValidationUtil.isTextFieldWhiteList(val)) errors.add(PropertyUtil.getProperty("sample", "organization.address2.invalid")); val = addrBean.getCity(); if (val != null && val.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(val)) errors.add(PropertyUtil.getProperty("sample", "organization.city.invalid")); val = addrBean.getStateProvince(); if (val != null && val.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(val)) errors.add(PropertyUtil.getProperty("sample", "organization.state.invalid")); val = addrBean.getCountry(); if (val != null && val.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(val)) errors.add(PropertyUtil.getProperty("sample", "organization.country.invalid")); val = addrBean.getZip(); if (val != null && val.length() > 0 && !InputValidationUtil.isZipValid(addrBean.getZip())) errors.add(PropertyUtil.getProperty("sample", "postalCode.invalid")); } String name = simplePOC.getFirstName(); if (name != null && name.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(name)) errors.add(PropertyUtil.getProperty("sample", "firstName.invalid")); name = simplePOC.getLastName(); if (name != null && name.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(name)) errors.add(PropertyUtil.getProperty("sample", "lastName.invalid")); name = simplePOC.getMiddleInitial(); if (name != null && name.length() > 0 && !InputValidationUtil.isRelaxedAlphabetic(name)) errors.add(PropertyUtil.getProperty("sample", "middleInitial.invalid")); String phone = simplePOC.getPhoneNumber(); if (phone.length() > 0 && !InputValidationUtil.isPhoneValid(phone)) errors.add(PropertyUtil.getProperty("sample", "phone.invalid")); // String email = simplePOC.getEmail(); EmailValidator emailValidator = EmailValidator.getInstance(); if (email != null && email.length() > 0 && !emailValidator.isValid(email)) errors.add("Email is invalid"); return errors; }
From source file:gov.nih.nci.cabig.caaers.web.rule.notification.NotificationsTab.java
@Override protected void validate(ReportDefinitionCommand command, BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups, Errors errors) { if (CollectionUtils.isEmpty(command.getReportDefinition().getPlannedNotifications())) return;//from ww w . j a v a2s . co m List<PlannedNotification> plannedNotifications = command.getEmailNotifications(); if (CollectionUtils.isEmpty(plannedNotifications)) return; EmailValidator emailValidator = EmailValidator.getInstance(); int i = 0; for (PlannedNotification plannedNotification : plannedNotifications) { i++; PlannedEmailNotification nf = (PlannedEmailNotification) plannedNotification; // Message if (nf.getNotificationBodyContent() == null || StringUtils.isEmpty(nf.getNotificationBodyContent().getBody())) { errors.rejectValue("tempProperty", "RPD_003", new Object[] { i }, "Message Invalid in Email Notification(" + i + ")"); } // Recipients if (nf.getRecipients() == null) { errors.rejectValue("tempProperty", "RPD_004", new Object[] { i }, "Invalid Recipient Information in Email Notification (" + i + ")"); } else { for (Recipient recipient : nf.getRecipients()) { if (StringUtils.isEmpty(recipient.getContact())) { errors.rejectValue("tempProperty", "RPD_004", new Object[] { i }, "Invalid Recipient Information in Email Notification (" + i + ")"); break; } // valid email? if (recipient instanceof ContactMechanismBasedRecipient) { if (!emailValidator.isValid(recipient.getContact())) { errors.rejectValue("tempProperty", "RPD_005", new Object[] { recipient.getContact(), i }, "Invalid email address [" + recipient.getContact() + "] in Email Notification (" + i + ")"); break; } } } } // subject line if (StringUtils.isEmpty(nf.getSubjectLine())) { errors.rejectValue("tempProperty", "RPD_006", new Object[] { i }, "Subject line Invalid in Email Notification(" + i + ")"); } } }
From source file:net.sziebert.tutorials.web.JoinFormValidator.java
public void validate(Object obj, Errors errors) { logger.debug("Validating join form."); JoinForm form = (JoinForm) obj;// ww w . j a v a 2 s . c om // Insure that a value with specified. rejectIfEmptyOrWhitespace(errors, "username", "error.username.empty"); rejectIfEmptyOrWhitespace(errors, "email", "error.email.empty"); rejectIfEmptyOrWhitespace(errors, "password", "error.password.empty"); rejectIfEmptyOrWhitespace(errors, "confirm", "error.confirm.empty"); // Insure the inputs don't contain any illegal characters. if (!isAlphanumeric(form.getUsername())) errors.rejectValue("username", "error.username.illegal.chars"); if (!isAlphanumeric(form.getPassword())) errors.rejectValue("password", "error.password.illegal.chars"); // Insure that the entries are within the valid length range. if (isNotBlank(form.getUsername()) && form.getUsername().length() < 4) errors.rejectValue("username", "error.username.too.short"); if (isNotBlank(form.getPassword()) && form.getPassword().length() < 6) errors.rejectValue("password", "error.password.too.short"); // Insure the password and confirmation match. if (isNotBlank(form.getPassword()) && isNotBlank(form.getConfirm())) { if (!form.getPassword().equals(form.getConfirm())) { errors.reject("error.password.mismatch"); } } // Insure the email address is valid. if (isNotBlank(form.getEmail())) { EmailValidator ev = EmailValidator.getInstance(); if (!ev.isValid(form.getEmail())) { errors.rejectValue("email", "error.email.invalid"); } } // Insure that the terms of use have been accepted. if (!form.getAgreeToTerms()) { errors.rejectValue("agreeToTerms", "error.agree.to.terms"); } }