本文整理汇总了Java中org.apache.commons.validator.EmailValidator类的典型用法代码示例。如果您正苦于以下问题:Java EmailValidator类的具体用法?Java EmailValidator怎么用?Java EmailValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmailValidator类属于org.apache.commons.validator包,在下文中一共展示了EmailValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateEmailApache
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
public static String validateEmailApache(String email){
email = email.trim();
EmailValidator eValidator = EmailValidator.getInstance();
if(eValidator.isValid(email)){
return email + " is a valid email address.";
}else{
return email + " is not a valid email address.";
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:10,代码来源:App.java
示例2: validate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
/**
* Validates the input
* @param object the user to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
UserDTO user = (UserDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
"googleId must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
"User Full Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
"User Given Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
"User Family Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
"User Image URL must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
"User Email must not be empty");
ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
"User Role must not be empty.");
// doing specific input validaiton, so we need to make sure all of the fields are there
if(!errors.hasErrors()) {
if(user.getRole() < 0 || user.getRole() > 1) {
errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
}
if(!EmailValidator.getInstance().isValid(user.getEmail())) {
errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
}
if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
}
}
}
示例3: validate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
@Override
public void validate(Object o, Errors errors) {
UpdateUserDTO user = (UpdateUserDTO) o;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
"User Id must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
"googleId must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
"User Full Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
"User Given Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
"User Family Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
"User Image URL must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
"User Email must not be empty");
ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
"User Role must not be empty.");
// doing specific input validaiton, so we need to make sure all of the fields are there
if(!errors.hasErrors()) {
if(user.getRole() < 0 || user.getRole() > 1) {
errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
}
if(!EmailValidator.getInstance().isValid(user.getEmail())) {
errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
}
if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
}
}
}
示例4: doValidate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void doValidate(MailInForm form, Errors errors) {
validateServerSettings(form, errors);
if (MailInController.MODE_SINGLE.equals(form.getMode())) {
if (!EmailValidator.getInstance().isValid(form.getSingleModeAddress())) {
errors.rejectValue("singleModeAddress", "error.email.not.valid");
}
} else if (MailInController.MODE_MULTI.equals(form.getMode())) {
if (StringUtils.isBlank(form.getMultiModeDomain())) {
errors.rejectValue("multiModeDomain", "string.validation.empty");
}
if (!EmailValidator.getInstance().isValid(
"a" + form.getMultiModeSuffix() + "@" + form.getMultiModeDomain())) {
errors.rejectValue("multiModeDomain",
"client.system.communication.mail.in.mode.multi.error.match");
errors.rejectValue("multiModeSuffix",
"client.system.communication.mail.in.mode.multi.error.match");
}
}
}
示例5: validate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
public void validate(Object obj, Errors errors) {
OrderInfoForm orderInfoForm = (OrderInfoForm) obj;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
if (!errors.hasErrors()) {
if (!EmailValidator.getInstance().isValid(orderInfoForm.getEmailAddress())) {
errors.rejectValue("emailAddress", "emailAddress.invalid", null, null);
}
}
}
示例6: validatePreferenceValues
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
/**
* @see org.kuali.rice.kcb.deliverer.MessageDeliverer#validatePreferenceValues(java.util.HashMap)
*/
public void validatePreferenceValues(HashMap<String, String> prefs) throws ErrorList {
boolean error = false;
ErrorList errorList = new ErrorList();
String[] validformats = {"text","html"};
if (!prefs.containsKey(getName()+"."+EMAIL_ADDR_PREF_KEY)) {
errorList.addError("Email Address is a required field.");
error = true;
} else {
String addressValue = (String) prefs.get(getName()+"."+EMAIL_ADDR_PREF_KEY);
EmailValidator validator = EmailValidator.getInstance();
if (!validator.isValid(addressValue)) {
errorList.addError("Email Address is required and must be properly formatted - \"[email protected]\".");
error = true;
}
}
// validate format
if (!prefs.containsKey(getName()+"."+EMAIL_DELIV_FRMT_PREF_KEY)) {
errorList.addError("Email Delivery Format is required.");
error = true;
} else {
String formatValue = (String) prefs.get(getName()+"."+EMAIL_DELIV_FRMT_PREF_KEY);
Set<String> formats = new HashSet<String>();
for (int i=0; i < validformats.length ; i++) {
formats.add(validformats[i]);
}
if (!formats.contains(formatValue)) {
errorList.addError("Email Delivery Format is required and must be entered as \"text\" or \"html\".");
error = true;
}
}
if (error) throw errorList;
}
示例7: isValidEmail
import org.apache.commons.validator.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.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);
}
示例8: generateFileNameFromEmail
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
public static String generateFileNameFromEmail(String userEmail) throws ValidationException{
String fileName = null;
if(userEmail != null && EmailValidator.getInstance().isValid(userEmail)){
// Get a random number of up to 7 digits
int sevenDigitRandom = new Double(Math.random() * 10000000).intValue();
// Get the last 7 digits of the Java timestamp
String s = String.valueOf(System.currentTimeMillis());
String lastSevenOfTimeStamp = s.substring(s.length()-7, s.length());
// Get the string before the @ sign in the user's email address
String userEmailBeforeAtSign = userEmail.substring(0, userEmail.indexOf('@'));
// Put it all together
fileName = userEmailBeforeAtSign + "_" + sevenDigitRandom + lastSevenOfTimeStamp;
}
else{
throw new ValidationException("Invalid Email Address");
}
return fileName;
}
示例9: convertSignupEmail
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
/**
* Helper to convert a signup email notification into a Sakai EmailMessage, which can encapsulate attachments.
*
* <p>Due to the way the email objects are created, ie one per email that needs to be sent, not one per user, we cannot store any
* user specific attachments within the email objects themselves. So this method assembles an EmailMessage per user
*
* @param email - the signup email obj we will extract info from
* @param recipient - list of user to receive the email
* @return
*/
private EmailMessage convertSignupEmail(SignupEmailNotification email, User recipient) {
EmailMessage message = new EmailMessage();
//setup message
message.setHeaders(email.getHeader());
message.setBody(email.getMessage());
// Pass a flag to the EmailService to indicate that we want the MIME multipart subtype set to alternative
// so that an email client can present the message as a meeting invite
message.setHeader("multipart-subtype", "alternative");
//note that the headers are largely ignored so we need to repeat some things here that are actually in the headers
//if these are eventaully converted to proper email templates, this should be alleviated
message.setSubject(email.getSubject());
log.debug("email.getFromAddress(): " + email.getFromAddress());
message.setFrom(email.getFromAddress());
message.setContentType("text/html; charset=UTF-8");
if(!email.isModifyComment()){
//skip ICS attachment file for user comment email
for(Attachment a: collectAttachments(email, recipient)){
message.addAttachment(a);
}
}
//add recipient, only if valid email
String emailAddress = recipient.getEmail();
if(StringUtils.isNotBlank(emailAddress) && EmailValidator.getInstance().isValid(emailAddress)) {
message.addRecipient(EmailAddress.RecipientType.TO, recipient.getDisplayName(), emailAddress);
} else {
log.debug("Invalid email for user: " + recipient.getDisplayId() + ". No email will be sent to this user");
return null;
}
return message;
}
示例10: validate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
@Override
public void validate(StartupForm target, List<String> errors, ConfigSource configSource) {
// only validate without active admin
if (userService.hasActiveMotechAdmin()) {
return;
}
if (StringUtils.isBlank(target.getAdminLogin())) {
errors.add(String.format(ERROR_REQUIRED, ADMIN_LOGIN));
} else if (userService.hasUser(target.getAdminLogin())) {
errors.add("server.error.user.exist");
} else if (userService.hasEmail(target.getAdminEmail())) {
errors.add("server.error.email.exist");
}
if (StringUtils.isBlank(target.getAdminPassword())) {
errors.add(String.format(ERROR_REQUIRED, ADMIN_PASSWORD));
} else if (StringUtils.isBlank(target.getAdminConfirmPassword())) {
errors.add(String.format(ERROR_REQUIRED, ADMIN_CONFIRM_PASSWORD));
} else if (!target.getAdminPassword().equals(target.getAdminConfirmPassword())) {
errors.add("server.error.invalid.password");
}
if (!EmailValidator.getInstance().isValid(target.getAdminEmail())) {
errors.add("server.error.invalid.email");
}
}
示例11: validateEmail
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
/**
* Validate Email field data is acceptable
*
* @param context FacesContext
* @param component UIComponent
* @param value Object
* @throws ValidatorException
*/
public void validateEmail(FacesContext context, UIComponent component, Object value) throws ValidatorException
{
EmailValidator emailValidator = EmailValidator.getInstance();
if (!emailValidator.isValid((String) value))
{
String err =Application.getMessage(context, MSG_ERROR_MAIL_NOT_VALID);
throw new ValidatorException(new FacesMessage(err));
}
}
示例12: validate
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
@Override
public Violation<T> validate(T o, String propertyName) {
EmailValidator v = EmailValidator.getInstance();
String emailAddress = getProperty(o, propertyName);
if(!v.isValid(emailAddress)){
return new ConstraintViolation<T>(o, propertyName, ConstraintViolationType.NON_VALID_EMAIL_ADDRESS);
}
return null;
}
示例13: isValidEmailAddress
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
public static boolean isValidEmailAddress(String emailAddr){
EmailValidator eValidator = EmailValidator.getInstance();
return eValidator.isValid(emailAddr);
}
示例14: handleSubmit
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(
HttpSession session,
@RequestParam String email,
Model model) {
logger.info("handleSubmit");
if (!EmailValidator.getInstance().isValid(email)) {
// TODO: display error message
return "content/contributor/add-email";
}
Contributor existingContributor = contributorDao.read(email);
if (existingContributor != null) {
// TODO: display error message
return "content/contributor/add-email";
}
Contributor contributor = (Contributor) session.getAttribute("contributor");
boolean isRedirectFromRegistrationPage = contributor.getEmail() == null;
contributor.setEmail(email);
contributorDao.create(contributor);
session.setAttribute("contributor", contributor);
SignOnEvent signOnEvent = new SignOnEvent();
signOnEvent.setContributor(contributor);
signOnEvent.setCalendar(Calendar.getInstance());
signOnEventDao.create(signOnEvent);
if (isRedirectFromRegistrationPage) {
// Send welcome e-mail
String to = contributor.getEmail();
String from = "elimu.ai <[email protected]>";
String subject = "Welcome to the community";
String title = "Welcome!";
String firstName = StringUtils.isBlank(contributor.getFirstName()) ? "" : contributor.getFirstName();
String htmlText = "<p>Hi, " + firstName + "</p>";
htmlText += "<p>Thank you very much for registering as a contributor to the elimu.ai community. We are glad to see you join us!</p>";
htmlText += "<p>With your help, this is what we aim to achieve:</p>";
htmlText += "<p><blockquote>\"The mission of the elimu.ai project is to build software that will enable children without access to school to learn how to read and write <i>on their own</i>.\"</blockquote></p>";
htmlText += "<p><img src=\"http://elimu.ai/static/img/banner-en.jpg\" alt=\"\" style=\"width: 564px; max-width: 100%;\" /></p>";
htmlText += "<h2>Chat</h2>";
htmlText += "<p>At http://slack.elimu.ai you can chat with the other community members.</p>";
htmlText += "<h2>Feedback</h2>";
htmlText += "<p>If you have any questions or suggestions, please contact us by replying to this e-mail or messaging us in the Slack chat room.</p>";
Mailer.sendHtml(to, null, from, subject, title, htmlText);
if (EnvironmentContextLoaderListener.env == Environment.PROD) {
// Post notification in Slack
String name = "";
if (StringUtils.isNotBlank(contributor.getFirstName())) {
name += "(";
name += contributor.getFirstName();
if (StringUtils.isNotBlank(contributor.getLastName())) {
name += " " + contributor.getLastName();
}
name += ")";
}
String text = URLEncoder.encode("A new contributor " + name + " just joined the community: ") + "http://elimu.ai/content/community/contributors";
String iconUrl = contributor.getImageUrl();
SlackApiHelper.postMessage(null, text, iconUrl, null);
}
}
return "redirect:/content";
}
示例15: ValidateUser
import org.apache.commons.validator.EmailValidator; //导入依赖的package包/类
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
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";
}