Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jfrog.hudson.util;
 
 
Utility class for form validations.

Author(s):
Yossi Shaul
public abstract class FormValidations {
    private static final Pattern VALID_EMAIL_PATTERN = Pattern.compile(
            "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)",
            .);

    
Validates a space separated list of emails.

Parameters:
emails Space separated list of emails
Returns:
hudson.util.FormValidation.ok() if valid or empty, error otherwise
    public static FormValidation validateEmails(String emails) {
        if (!Strings.isNullOrEmpty(emails)) {
            String[] recipients = StringUtils.split(emails" ");
            for (String email : recipients) {
                FormValidation validation = validateInternetAddress(email);
                if (validation != FormValidation.ok()) {
                    return validation;
                }
            }
        }
        return FormValidation.ok();
    }

    
Validates an internet address (url, email address, etc.).

Parameters:
address The address to validate
Returns:
hudson.util.FormValidation.ok() if valid or empty, error otherwise
    public static FormValidation validateInternetAddress(String address) {
        if (Strings.isNullOrEmpty(address)) {
            return FormValidation.ok();
        }
        Matcher matcher = .matcher(address);
        if (matcher.matches()) {
            return FormValidation.ok();
        } else {
            return FormValidation.error("Email address is invalid");
        }
    }
New to GrepCode? Check out our FAQ X