gpt4 book ai didi

html - 我想使用 joi 验证时间字段

转载 作者:行者123 更新时间:2023-12-05 03:49:43 38 4
gpt4 key购买 nike

我已经采用了日期和时间输入字段。我使用 joi 库进行输入验证是日期和时间不能单独为 null。我成功地应用了日期验证,但我无法应用时间验证。我怎样才能实现时间验证。

这是我的日期和时间输入字段的 html 文件代码。

html += '<td><input type="text" id="tier3City'+cnt+'"  readonly="readonly" name="tier3City" 
class="form-control" /></td>';
html += '<td><input type="date" id="fromDate'+cnt+'" name="fromDate" class="form-control" /></td>';
html += '<td><input type="time" id="fromTime'+cnt+'" name="fromTime" class="form-control" /></td>';
html += '<td><input type="date" id="toDate'+cnt+'" name="toDate" class="form-control" /></td>';
html += '<td><input type="time" id="toTime'+cnt+'" name="toTime" class="form-control" /></td>';

这是我的 ejs 文件代码。

  else if(stayOption == 'Stay')
{
schema=joi.object({
stayOption:joi.string().required().label('Please Choose Stay Option'),
projectTask:joi.string().required().label('Please select Activity Code.'),
placeJourney: joi.string().required().label('Please select Place of Journey.'),
fromDated:joi.date().required().label('Please select FROM(Departure Time from Residence)'),
fromDat:joi.date().max('now').required().label('Please select FROM(Departure Time from Residence) less than or equals to Today'),
fromTimes:joi.time().required().label('Please select FROM(Departure Time from Residence) Time'),
toDated:joi.date().required().label('Please select TO(Arrival Time to Residence)'),
toDate:joi.date().max('now').required().label('TO(Arrival Time to Residence must be less than or equals to Today'),
fromDate:joi.date().required().less(joi.ref('toDate')).label('From(Departure Time from Residence) must be less than To (Arrival Time to Residence)'),
toTimes:joi.time().required().label('Please select TO (Arrival Time to Residence)Time'),
actualAMTForBL:joi.number().required().label('Please enter Actual Boarding lodging Amount'),
imgpath:joi.string().invalid('demo').label('Please Upload File/Attachments').required(),
})
result=schema.validate({stayOption:stayOption,projectTask:projectTask,placeJourney:placeJourney,fromDated:fromDate,fromDat:fromDate,toDated:toDate,fromDate:fromDate,fromTimes:fromTime,toDate:toDate,toTimes:toTime,actualAMTForBL:actualAMTForBL,imgpath:imgpath});

最佳答案

您必须使用 RegEx 来验证时间(Joi.string().regex() 而不是 Joi.time())。

您的问题的解决方案是 here .

关于html - 我想使用 joi 验证时间字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63773092/

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