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

io.convergence_platform.common.validations.ValidateEmailValidator Maven / Gradle / Ivy

Go to download

Holds the common functionality needed by all Convergence Platform-based services written in Java.

The newest version!
package io.convergence_platform.common.validations;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidateEmailValidator implements ConstraintValidator {
    public static void pathVariable(String value, String varName) {
        boolean valid = true;
        if ("".equals(value)) {
            valid = false;
        } else {
            valid = validate(value);
        }

        ValidationHelper.raiseValidationErrorForPathVariable(valid, "email", varName);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return validate(value);
    }

    private static boolean validate(String value) {
        Pattern pattern = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}");
        Matcher mat = pattern.matcher(value);

        return mat.matches();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy