All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.data.validation.URLCheck Maven / Gradle / Ivy

There is a newer version: 2.6.3
Show newest version
package play.data.validation;

import net.sf.oval.Validator;
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
import net.sf.oval.context.OValContext;

import java.util.regex.Pattern;

@SuppressWarnings("serial")
public class URLCheck extends AbstractAnnotationCheck {

    static final String mes = "validation.url";
    static Pattern urlPattern = Pattern.compile("^(http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-z" +
            "A-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\\\+&%\\$#\\=~\\!])*$");

    @Override
    public void configure(URL url) {
        setMessage(url.message());
    }

    @Override
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        if (value == null || value.toString().length() == 0) {
            return true;
        }
        return urlPattern.matcher(value.toString()).matches();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy