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

cn.ipokerface.common.validation.validator.PatternConstraintValidator Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package cn.ipokerface.common.validation.validator;


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

/**
 * Created by       PokerFace
 * Create Date      2019-11-25.
 * Email:           [email protected]
 * Version          1.0.0
 * 

* Description: */ public class PatternConstraintValidator implements ConstraintValidator { /** * Validate string by some pattern * Pattern.compile() * pattern.match() * * @param value parameter value * @param constraintAnnotation parameter annotation * @return */ public boolean validate(String value, cn.ipokerface.common.validation.constraint.Pattern constraintAnnotation) { if (value == null || "".equals(value)) return true; String patternValue = constraintAnnotation.value(); if (patternValue == null || "".equals(patternValue)) return true; Pattern pattern = java.util.regex.Pattern.compile(patternValue); Matcher matcher = pattern.matcher(value); if (matcher.matches()) return true; return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy