From 9b4433fddf5b401edb0aace8a404ac733b122702 Mon Sep 17 00:00:00 2001 From: 田源 <tianyuan@vci-tech.com> Date: 星期四, 03 四月 2025 14:35:02 +0800 Subject: [PATCH] 添加非密字段显示 --- Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RegexUtil.java | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-) diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RegexUtil.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RegexUtil.java new file mode 100644 index 0000000..03052f1 --- /dev/null +++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/utils/RegexUtil.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2018-2028, DreamLu All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: DreamLu 鍗㈡槬姊� (596392912@qq.com) + */ +package org.springblade.core.tool.utils; + +import org.springframework.lang.Nullable; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 姝e垯琛ㄨ揪寮忓伐鍏� + * + * @author L.cm + */ +public class RegexUtil { + /** + * 鐢ㄦ埛鍚� + */ + public static final String USER_NAME = "^[a-zA-Z\\u4E00-\\u9FA5][a-zA-Z0-9_\\u4E00-\\u9FA5]{1,11}$"; + + /** + * 瀵嗙爜 + */ + public static final String USER_PASSWORD = "^.{6,32}$"; + + /** + * 閭 + */ + public static final String EMAIL = "^\\w+([-+.]*\\w+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+$"; + + /** + * 鎵嬫満鍙� + */ + public static final String PHONE = "^1[3456789]\\d{9}$"; + + /** + * 鎵嬫満鍙锋垨鑰呴偖绠� + */ + public static final String EMAIL_OR_PHONE = EMAIL + "|" + PHONE; + + /** + * URL璺緞 + */ + public static final String URL = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})(:[\\d]+)?([\\/\\w\\.-]*)*\\/?$"; + + /** + * 韬唤璇佹牎楠岋紝鍒濈骇鏍¢獙锛屽叿浣撹鍒欐湁涓�濂楃畻娉� + */ + public static final String ID_CARD = "^\\d{15}$|^\\d{17}([0-9]|X)$"; + + /** + * 鍩熷悕鏍¢獙 + */ + public static final String DOMAIN = "^[0-9a-zA-Z]+[0-9a-zA-Z\\.-]*\\.[a-zA-Z]{2,4}$"; + + /** + * 缂栬瘧浼犲叆姝e垯琛ㄨ揪寮忓拰瀛楃涓插幓鍖归厤,蹇界暐澶у皬鍐� + * + * @param regex 姝e垯 + * @param beTestString 瀛楃涓� + * @return {boolean} + */ + public static boolean match(String regex, String beTestString) { + Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(beTestString); + return matcher.matches(); + } + + /** + * 缂栬瘧浼犲叆姝e垯琛ㄨ揪寮忓湪瀛楃涓蹭腑瀵绘壘锛屽鏋滃尮閰嶅埌鍒欎负true + * + * @param regex 姝e垯 + * @param beTestString 瀛楃涓� + * @return {boolean} + */ + public static boolean find(String regex, String beTestString) { + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(beTestString); + return matcher.find(); + } + + /** + * 缂栬瘧浼犲叆姝e垯琛ㄨ揪寮忓湪瀛楃涓蹭腑瀵绘壘锛屽鏋滄壘鍒拌繑鍥炵涓�涓粨鏋� + * 鎵句笉鍒拌繑鍥瀗ull + * + * @param regex 姝e垯 + * @param beFoundString 瀛楃涓� + * @return {boolean} + */ + @Nullable + public static String findResult(String regex, String beFoundString) { + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(beFoundString); + if (matcher.find()) { + return matcher.group(); + } + return null; + } + +} -- Gitblit v1.9.3