gpt4 book ai didi

json - 时间段格式应为 dd,MMM,yyyy,hh,mm 格式

转载 作者:行者123 更新时间:2023-12-04 19:59:55 24 4
gpt4 key购买 nike

您好,我正在发送 JSON 数据,JSON 必须在后端进行验证。时间段应采用这种格式--- dd,MMM,yyyy,hh,mm

这是我的JSON

{
"equipmentID":"234",
"modality":"healthcaare",
"facilityID":"manipal",
"countryCode":"abc",
"isoCode":"1234",
"problemType":"234",
"problemArea":"priyanka",
"equipmentStatus":"sdsd",
"name":"taneja",
"phoneNumber":"13333344",
"extension":"12123",
"description":"x ray machine error",
"shortDescription":"2",
"timePeriod":"03-12-2011 04-37",
"serviceCode":"sdfdf",
"locale":"werfd",
"requestingApp":"icenter",
"examNumber":"sdd",
"seriesNumber":"dfdf",
"imageNumber":"dfdfd"
}

这是验证类 公共(public)类 RequestValidator 实现验证器 {

    @Override
public ValidationResult validate(String objectName, RequestData rqdata) {
// TODO Auto-generated method stub

ValidationResult result = new ValidationResult();

if (rqdata == null) {
result.addError("error.invalidObjectGraph", "Object graph not initialized correctly");
return result;
}
Validation.rule("EquipmentId", rqdata.getEquipmentID()).required().run(result);
Validation.rule("Modality", rqdata.getModality()).required().run(result);
Validation.rule("FacilityID", rqdata.getFacilityID()).required().run(result);
Validation.rule("CountryCode", rqdata.getCountryCode()).required().maxLength(3).matches("^[a-zA-Z]*$")
.run(result);
Validation.rule("ProblemType", rqdata.getProblemType()).required().run(result);
Validation.rule("Name", rqdata.getName()).required().maxLength(20).run(result);
Validation.rule("PhoneNumber", rqdata.getPhoneNumber()).required().maxLength(25).matches("[0-9]+").run(result);
Validation.rule("Extension", rqdata.getExtension()).required().maxLength(10).matches("[0-9]+").run(result);
Validation.rule("Description", rqdata.getDescription()).required().maxLength(300).run(result);
Validation.rule("ShortDescription", rqdata.getShortDescription()).required().maxLength(80).run(result);
Validation.rule("TimePeriod", rqdata.getTimePeriod()).required().matches("dd-MMM-yyyy hh-mm").run(result);
Validation.rule("Locale", rqdata.getLocale()).required().run(result);

System.out.println("value of requesting app is:" + rqdata.getRequestingApp());
Validation.rule("RequestingApp", rqdata.getRequestingApp()).required().matches("icenter").run(result);
System.out.println(result.getErrorDetails());
return result;
}
}

但我收到一个错误消息,指出日期格式不正确。请帮帮我。谢谢

最佳答案

匹配需要在其中包含一个正则表达式。

试试这个

^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$

这适合检查当月的 MMM

Time 不同方式的参数之一。请考虑日期数据交换的纪元格式。这将是一个更好的选择。

[编辑]

改变这个

Validation.rule("TimePeriod", rqdata.getTimePeriod()).required().matches("dd-MMM-yyyy hh-mm").run(result);

String regEx = "^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$";
Validation.rule("TimePeriod", rqdata.getTimePeriod()).required().matches(regEx).run(result);

关于json - 时间段格式应为 dd,MMM,yyyy,hh,mm 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36149673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com