Commit f8e261e5 authored by yanzg's avatar yanzg

身份证识别

parent 1784577d
......@@ -230,9 +230,9 @@ public final class CheckerHelper {
/**
* 检测是否符合时间类型
*
* @param paramName
* @param paramVal
* @param queryType
* @param paramName 参数名称
* @param paramVal
* @param queryType 格式类型
* @return
*/
public CheckerHelper notDateCheck(String paramName, String paramVal, String queryType) {
......@@ -364,7 +364,7 @@ public final class CheckerHelper {
*
* @param paramName 参数名称
* @param paramVal 参数值
* @return
* @return 当前对象
*/
public CheckerHelper checkDate(String paramName, String paramVal) {
return checkDate(paramName, paramVal, StringHelper.EMPTY);
......@@ -376,7 +376,7 @@ public final class CheckerHelper {
* @param paramName 参数名称
* @param paramVal 参数值
* @param formatStr 日期格式
* @return
* @return 当前对象
*/
public CheckerHelper checkDate(String paramName, String paramVal, String formatStr) {
if (!isValid()) {
......@@ -386,10 +386,17 @@ public final class CheckerHelper {
return this;
}
try {
getDate(paramVal, formatStr);
Date date = getDate(paramVal, formatStr);
String dateResult = DateHelper.getDateTimeString(formatStr, date);
if (!dateResult.startsWith(paramVal)){
String formatTo = StringHelper.getFirst(formatStr,DateHelper.FORMAT_SECOND_STRING);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatTo);
this.setValid(false);
}
} catch (ParseException e) {
e.printStackTrace();
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatStr);
String formatTo = StringHelper.getFirst(formatStr,DateHelper.FORMAT_SECOND_STRING);
this.checkResult = language.format(PARAM_NOT_DATE, paramName, formatTo);
this.setValid(false);
}
return this;
......@@ -400,7 +407,6 @@ public final class CheckerHelper {
SimpleDateFormat format = new SimpleDateFormat(formatStr);
return format.parse(paramVal);
} else {
formatStr = DateHelper.FORMAT_SECOND_STRING;
return DateAutoHelper.getAutoDate(paramVal);
}
}
......
......@@ -853,11 +853,11 @@ public class DateHelper {
* @return 转换后的结果
*/
public static String getDateTimeString(String format, Date date) {
String to = "";
if (date != null) {
to = new SimpleDateFormat(format).format(date);
String formatTo = StringHelper.getFirst(format,FORMAT_SECOND_STRING);
return new SimpleDateFormat(formatTo).format(date);
}
return to;
return StringHelper.EMPTY;
}
/**
......
package helper;
import com.yanzuoguang.util.helper.CheckerHelper;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import org.junit.Test;
import java.util.Date;
public class TestString {
@Test
......@@ -15,4 +19,21 @@ public class TestString {
System.out.printf("长度:%d 条数:%d%n", content.length(), page);
System.out.printf("长度:%d 条数:%d%n", content1.length(), page1);
}
@Test
public void testDt(){
String dt = "2024-24-15 10:24";
Date date = DateHelper.getDateTime(dt);
String dtTo = DateHelper.getDateTimeString(date);
if(dtTo.startsWith(dt)){
System.out.println("测试通过");
}else{
System.out.println("测试失败");
}
}
@Test
public void testDtCheckHelper(){
String dt = "2024-24-15 10:24";
CheckerHelper.newInstance().checkDate("dt",dt).checkException();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment