@@ -304,15 +304,15 @@ public static boolean isNotEmpty(String s, boolean trim) {
304304
305305 //判断字符类型 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
306306
307- public static final Pattern alphaPattern ;
308- public static final Pattern bigAlphaPattern ;
309- public static final Pattern namePattern ;
310- public static final Pattern smallAlphaPattern ;
307+ public static final Pattern ALPHA_PATTERN ;
308+ public static final Pattern NAME_PATTERN ;
309+ public static final Pattern BIG_ALPHA_PATTERN ;
310+ public static final Pattern SMALL_ALPHA_PATTERN ;
311311 static {
312- alphaPattern = Pattern .compile ("[a-zA-Z]" );
313- bigAlphaPattern = Pattern .compile ("[A-Z] " );
314- namePattern = Pattern .compile ("^[0-9a-zA-Z_]+$ " );//已用55个中英字符测试通过
315- smallAlphaPattern = Pattern .compile ("[a-z]" );
312+ ALPHA_PATTERN = Pattern .compile ("[a-zA-Z]" );
313+ NAME_PATTERN = Pattern .compile ("^[0-9a-zA-Z_]+$ " );//已用55个中英字符测试通过
314+ BIG_ALPHA_PATTERN = Pattern .compile ("[A-Z] " );
315+ SMALL_ALPHA_PATTERN = Pattern .compile ("[a-z]" );
316316 }
317317
318318 //判断手机格式是否正确
@@ -392,6 +392,29 @@ public static boolean isNumberOrAlpha(String s) {
392392 return isNumer (s ) || isAlpha (s );
393393 }
394394
395+ /**判断是否为单词,只能包含字母,数字或下划线
396+ * @param s
397+ * @return
398+ */
399+ public static boolean isWord (String s ) {
400+ return s != null && NAME_PATTERN .matcher (s ).matches ();
401+ }
402+ /**判断是否为首字母大写的单词
403+ * @param key
404+ * @return
405+ */
406+ public static boolean isBigWord (String s ) {
407+ return s != null && BIG_ALPHA_PATTERN .matcher (s .substring (0 , 1 )).matches () && isWord (s .substring (1 ));
408+ }
409+ /**判断是否为首字母小写的单词
410+ * @param key
411+ * @return
412+ */
413+ public static boolean isSmallWord (String s ) {
414+ return s != null && SMALL_ALPHA_PATTERN .matcher (s .substring (0 , 1 )).matches () && isWord (s .substring (1 ));
415+ }
416+
417+
395418 /**判断字符类型是否是身份证号
396419 * @param idCard
397420 * @return
@@ -722,11 +745,10 @@ public static String[] split(String s, String split) {
722745 * @return key + suffix,第一个字母小写
723746 */
724747 public static String addSuffix (String key , String suffix ) {
725- key = StringUtil . getNoBlankString (key );
748+ key = getNoBlankString (key );
726749 if (key .isEmpty ()) {
727750 return firstCase (suffix );
728751 }
729-
730752 return firstCase (key ) + firstCase (suffix , true );
731753 }
732754 /**
@@ -741,7 +763,7 @@ public static String firstCase(String key) {
741763 * @return
742764 */
743765 public static String firstCase (String key , boolean upper ) {
744- key = StringUtil . getString (key );
766+ key = getString (key );
745767 if (key .isEmpty ()) {
746768 return "" ;
747769 }
@@ -752,7 +774,6 @@ public static String firstCase(String key, boolean upper) {
752774 return key ;
753775 }
754776
755-
756777 //校正(自动补全等)字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
757778
758779}
0 commit comments