本文整理汇总了Java中org.apache.commons.validator.routines.EmailValidator类的典型用法代码示例。如果您正苦于以下问题:Java EmailValidator类的具体用法?Java EmailValidator怎么用?Java EmailValidator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmailValidator类属于org.apache.commons.validator.routines包,在下文中一共展示了EmailValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateAddress
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
/**
* Return true if address has valid format
* @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;
}
示例2: verifyFormData
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public void verifyFormData(HudsonSecurityRealmRegistration securityRealmRegistration, JSONObject object)
throws RegistrationException, InvalidSecurityRealmException {
final String activationCode = BaseFormField.ACTIVATION_CODE.fromJSON(object);
if (StringUtils.isEmpty(activationCode)) {
throw new RegistrationException(Messages.RRError_Hudson_ActiviationCodeInvalid());
}
final User user = RRHudsonUserProperty.getUserForActivationCode(activationCode);
final RRHudsonUserProperty hudsonUserProperty = RRHudsonUserProperty.getPropertyForUser(user);
if (hudsonUserProperty == null) {
throw new RegistrationException(Messages.RRError_Hudson_ActiviationCodeInvalid());
}
if (hudsonUserProperty.getActivated()) {
throw new RegistrationException(Messages.RRError_Hudson_UserIsActivated());
}
final Mailer.UserProperty mailerProperty = user.getProperty(Mailer.UserProperty.class);
if (mailerProperty == null) {
throw new RegistrationException(Messages.RRError_Hudson_UserNoEmailAddress());
}
final String emailAddress = Utils.fixEmptyString(mailerProperty.getAddress());
if (!EmailValidator.getInstance().isValid(emailAddress)) {
throw new RegistrationException(Messages.RRError_Hudson_UserInvalidEmail(emailAddress));
}
}
示例3: createMessage
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
private MimeMessage createMessage() throws MailException, UnsupportedEncodingException,
MessagingException {
final String content = getContent();
final String replyToAddress = replyTo;
final MimeMessageBuilder messageBuilder = new MimeMessageBuilder();
messageBuilder.setSubject(this.subject);
messageBuilder.setCharset(META_CHARSET);
messageBuilder.addRecipients(this.recipients);
if (EmailValidator.getInstance().isValid(replyToAddress)) {
Utils.logInfo("Reply to address " + replyToAddress);
messageBuilder.setReplyTo(replyToAddress);
}
final MimeMessage message = messageBuilder.buildMimeMessage();
message.setContent(content, META_CONTENT_TYPE);
return message;
}
示例4: getErrors
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public List<Error> getErrors() {
List<Error> errors = newArrayList();
if (isBlank(payload.getUsername())) {
errors.add(new Error("400", "username"));
}
if (isBlank(payload.getEmail())) {
errors.add(new Error("400", "email"));
} else if (!EmailValidator.getInstance().isValid(payload.getEmail())) {
errors.add(new Error("400", "email-bad-syntax"));
}
if (isBlank(payload.getPassword())) {
errors.add(new Error("400", "password"));
} else {
if (payload.getPassword().length() < PASSWORD_MIN_LENGTH) {
errors.add(new Error("400", "password-bad"));
}
}
return errors;
}
示例5: validate
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
/**
* Validate the bean's contents
* @return {@code true} if the contents are valid; {@code false} otherwise.
*/
private boolean validate() {
boolean ok = true;
// Email
if (!EmailValidator.getInstance().isValid(emailAddress)) {
ok = false;
setMessage(getComponentID("emailAddress"), "Email is not valid");
}
// Passwords must match
if (!password1.equals(password2)) {
ok = false;
setMessage(getComponentID("password1"), "Passwords must match");
setMessage(getComponentID("password2"), "Passwords must match");
}
return ok;
}
示例6: isValidEmail
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
/**
* Is this a valid email the service will recognize
*
* @param email
* @return
*/
private boolean isValidEmail(String email) {
if (email == null || email.equals("")) {
return false;
}
email = email.trim();
//must contain @
if (!email.contains("@")) {
return false;
}
//an email can't contain spaces
if (email.indexOf(" ") > 0) {
return false;
}
//use commons-validator
EmailValidator validator = EmailValidator.getInstance();
return validator.isValid(email);
}
示例7: isValidEmail
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
/**
* Is this a valid email the service will recognize
*
* @param email
* @return
*/
private boolean isValidEmail(String email) {
// TODO: Use a generic Sakai utility class (when a suitable one exists)
if (email == null || email.equals(""))
return false;
email = email.trim();
// must contain @
if (email.indexOf("@") == -1)
return false;
// an email can't contain spaces
if (email.indexOf(" ") > 0)
return false;
// use commons-validator
EmailValidator validator = EmailValidator.getInstance();
if (validator.isValid(email))
return true;
return false;
}
示例8: emailResponsesDo
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@RequestMapping(value = FULL_PATH + "/view/email/send", method = RequestMethod.GET)
public Request emailResponsesDo(@RequestParam(value = phoneNumber) String inputNumber,
@RequestParam String todoUid,
@RequestParam(value = userInputParam) String emailAddress) throws URISyntaxException {
User user = userManager.findByInputNumber(inputNumber, null);
log.info("User={}",user);
boolean isEmailValid = EmailValidator.getInstance().isValid(emailAddress);
if (isEmailValid || user.hasEmailAddress() && emailAddress.length() == 1) {
final String emailToPass = emailAddress.length() == 1 ? user.getEmailAddress() : emailAddress;
dataExportBroker.emailTodoResponses(user.getUid(), todoUid, emailToPass);
USSDMenu menu = new USSDMenu(messageAssembler.getMessage("todo.email.prompt.done", user));
return menuBuilder(addBackHomeExit(menu, todoUid, user));
} else {
String prompt = messageAssembler.getMessage("todo.email.prompt.error", new String[] { emailAddress }, user);
return menuBuilder(new USSDMenu(prompt, REL_PATH + "/view/email/send?todoUid=" + todoUid));
}
}
示例9: User
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
public User(String phoneNumber, String displayName, String emailAddress) {
if (StringUtils.isEmpty(phoneNumber) && StringUtils.isEmpty(emailAddress)) {
throw new IllegalArgumentException("Phone number and email address cannot both be null!");
}
if (!StringUtils.isEmpty(emailAddress) && !EmailValidator.getInstance().isValid(emailAddress)) {
throw new IllegalArgumentException("Email address, if provided, must be valid");
}
this.uid = UIDGenerator.generateId();
this.phoneNumber = phoneNumber;
this.emailAddress = emailAddress;
this.username = StringUtils.isEmpty(phoneNumber) ? emailAddress : phoneNumber;
this.displayName = removeUnwantedCharacters(displayName);
this.languageCode = "en";
this.messagingPreference = !StringUtils.isEmpty(phoneNumber) ? DeliveryRoute.SMS : DeliveryRoute.EMAIL_GRASSROOT; // as default
this.createdDateTime = Instant.now();
this.alertPreference = AlertPreference.NOTIFY_NEW_AND_REMINDERS;
this.hasUsedFreeTrial = false;
}
示例10: validateFormInputs
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public void validateFormInputs() {
setErrorMessageAndStepComplete(null);
if (WatchDogUtils
.isEmptyOrHasOnlyWhitespaces(getProgrammingExperience())) {
setErrorMessageAndStepComplete("Please fill in your years of programming experience");
}
if (!WatchDogUtils.isEmpty(emailInput.getText())) {
if (!EmailValidator.getInstance(false)
.isValid(emailInput.getText())) {
setErrorMessageAndStepComplete("Your mail address is not valid!");
}
}
if (WatchDogUtils.isEmpty(emailInput.getText())
&& mayContactButton.isSelected()) {
setErrorMessageAndStepComplete("You can only participate in the lottery if you enter your email address.");
}
updateStep();
}
示例11: validateFormInputs
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public void validateFormInputs() {
setErrorMessageAndPageComplete(null);
if (WatchDogUtils
.isEmptyOrHasOnlyWhitespaces(getProgrammingExperience())) {
setErrorMessageAndPageComplete(
"Please fill in your years of programming experience");
}
if (!WatchDogUtils.isEmpty(emailInput.getText())) {
if (!EmailValidator.getInstance(false)
.isValid(emailInput.getText())) {
setErrorMessageAndPageComplete(
"Your mail address is not valid!");
}
}
if (WatchDogUtils.isEmpty(emailInput.getText())
&& mayContactButton.getSelection()) {
setErrorMessageAndPageComplete(
"You can only participate in the lottery if you enter your email address.");
}
getWizard().getContainer().updateButtons();
}
示例12: validate
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
public static void validate(String type, String address, int period,
List<Integer> validPeriods) {
if (type.equals("EMAIL")) {
if (!EmailValidator.getInstance(true).isValid(address))
throw Exceptions.unprocessableEntity("Address %s is not of correct format", address);
}
if (type.equals("WEBHOOK")) {
if (!URL_VALIDATOR.isValid(address))
throw Exceptions.unprocessableEntity("Address %s is not of correct format", address);
if (period != 0 && !validPeriods.contains(period)){
throw Exceptions.unprocessableEntity("%d is not a valid period", period);
}
}
if (period != 0 && !type.equals("WEBHOOK")){
throw Exceptions.unprocessableEntity("Period can not be non zero for %s", type);
}
}
示例13: validate
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
if (((String) value).isEmpty()) {
throwValidatorException();
}
else {
if (UrlValidator.getInstance().isValid((String) value)) {
return;
}
else if (EmailValidator.getInstance().isValid((String) value)) {
return;
} else
{
throwValidatorException();
}
}
}
示例14: findEmail
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public String findEmail(final String username) {
final String email = this.jdbcTemplate.queryForObject(passwordManagementProperties.getJdbc().getSqlFindEmail(),
String.class, username);
if (StringUtils.isNotBlank(email) && EmailValidator.getInstance().isValid(email)) {
return email;
}
return null;
}
示例15: findEmail
import org.apache.commons.validator.routines.EmailValidator; //导入依赖的package包/类
@Override
public String findEmail(final String username) {
try {
final PasswordManagementProperties.Ldap ldap = passwordManagementProperties.getLdap();
final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldap.getUserFilter(),
Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME,
Arrays.asList(username));
LOGGER.debug("Constructed LDAP filter [{}] to locate account email", filter);
final ConnectionFactory factory = Beans.newLdaptivePooledConnectionFactory(ldap);
final Response<SearchResult> response = LdapUtils.executeSearchOperation(factory, ldap.getBaseDn(), filter);
LOGGER.debug("LDAP response to locate account email is [{}]", response);
if (LdapUtils.containsResultEntry(response)) {
final LdapEntry entry = response.getResult().getEntry();
LOGGER.debug("Found LDAP entry [{}] to use for the account email", entry);
final String attributeName = passwordManagementProperties.getReset().getEmailAttribute();
final LdapAttribute attr = entry.getAttribute(attributeName);
if (attr != null) {
final String email = attr.getStringValue();
LOGGER.debug("Found email address [{}] for user [{}]. Validating...", email, username);
if (EmailValidator.getInstance().isValid(email)) {
LOGGER.debug("Email address [{}] matches a valid email address", email);
return email;
}
LOGGER.error("Email [{}] is not a valid address", email);
} else {
LOGGER.error("Could not locate an LDAP attribute [{}] for [{}] and base DN [{}]",
attributeName, filter.format(), ldap.getBaseDn());
}
return null;
}
LOGGER.error("Could not locate an LDAP entry for [{}] and base DN [{}]", filter.format(), ldap.getBaseDn());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}