如何使用AngularJS格式化小时



我在标准小时格式(" hh:mm")的输入文本中遇到问题,作为客户端类型。另外,我必须验证到达时间不大于出发时间。这是一些样本:

<table>
    <tr><td>Arrival: <input type="text" ng-model="item.arrival" name="arrival">{{item.arrival | date: 'HH:mm'}}</td> //It doesn't work. The code doesn't force the formatting upon typing(the ":") and also it allows more than 4 characters
    <tr><td>Departure: <input type="text" ng-model="item.departure" name="departure">{{item.departure | date: 'HH:mm'}}</td></tr> //I must check if the value defined in arrival isn't greater than departure time.
</table>

有人可以显示一些处理此问题的代码吗?我更像是后端开发人员,我在谷歌上搜索了一些,但找不到太多。任何帮助将不胜感激。

您最好的选择可能是使用诸如UI掩码之类的东西掩盖输入,并允许用户仅输入数字,然后在提交后的到达和出发时间进行验证。

否则,您可以尝试制作自己的指令并将其应用于输入字段。

最新更新