文章目录
需求,不为空 长度大于6 只包含汉字
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StringUtils;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class Test15 {
public static final String STR_ENG_PATTERN = "^[\u4e00-\u9fa5]{0,}$";
@Test
public void lexiconTest() {
boolean b7 = validateStrEnglish("");
boolean b8 = validateStrEnglish("张三是暖宝宝的");
boolean b9 = validateStrEnglish("张三是暖宝宝");
System.out.println(b7);
System.out.println(b8);
System.out.println(b9);
}
public static boolean validateStrEnglish(final String str) {
//判空
if (StringUtils.isEmpty(str)) {
return Boolean.FALSE;
}
boolean matches = str.matches(STR_ENG_PATTERN);
if (str.length() <= 6) {
return Boolean.FALSE;
}
if (matches) {
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
}