diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/ValidationUtil.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/ValidationUtil.java index 2bcce88..429e5ca 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/ValidationUtil.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/ValidationUtil.java @@ -5,6 +5,9 @@ */ package com.shop.cereshop.commons.utils; +import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator; + +import java.math.BigDecimal; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -21,6 +24,15 @@ import java.util.stream.Stream; public class ValidationUtil { /** + * 验证是否为邮箱 + * @param email + * @return + */ + public static boolean isEmail(String email) { + return new EmailValidator().isValid(email, null); + } + + /** * 身份证号码校验 */ private static final Map cityMap = Stream.of(new String[][] { @@ -105,4 +117,19 @@ public class ValidationUtil { return null; } + + /** + * 检测价格区间 + * @param price + * @param min + * @param max + * @return + */ + public static boolean checkPrice(BigDecimal price, BigDecimal min, BigDecimal max) { + if (price == null || min == null || max == null) { + return false; + } + return price.compareTo(min) >= 0 && price.compareTo(max) <= 0; + } + }