From 49ae890e6afcfe9db0194a0dfeb451bd178775ee Mon Sep 17 00:00:00 2001 From: dy-hu Date: Thu, 13 Jun 2024 08:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=9F=8E=E7=AB=AF=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E8=AF=81=E5=8F=B7=E6=B7=BB=E5=8A=A0=E6=A0=A1=E9=AA=8C=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cereshop/commons/utils/ValidationUtil.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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; + } + }