Angular.JS-在输入数字字段中最多只允许一个特定的数字值 [英] Angular.JS - only allow up to a certain number value in an input number field

查看:34
本文介绍了Angular.JS-在输入数字字段中最多只允许一个特定的数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一种角度的方式来理解,我只能让用户输入一个不超过24的数字,或在我的其他输入中输入一个不超过60的数字来表示小时和分钟.

I'm trying to understand a way with angular where I can only let the user enter a number that isn't more than 24 or in my other input 60 to represent hours and minutes.

            <input type="number"
                   placeholder="HH"
                   ng-minlength="2"
                   ng-maxlength="2"
                   required
                   ng-model="session.timeHH">

            <input type="number"
                   placeholder="mm"
                   ng-minlength="2"
                   required
                   ng-maxlength="2"
                   ng-model="session.timeMM">

这是我目前的HTML.

This is my HTML at the moment.

用户可以在小时数输入中输入数字,例如99,这显然是错误的.我正在寻找一种方法来验证或阻止用户提交之前只能输入最多24个小时(小时)和59个分钟(分钟)的数字.

The user can enter in the hours input a number like 99 which is obviously going to be wrong. I'm looking for a way to validate or prevent the user before submit to only be able to enter numbers up to 24 for hours and 59 for minutes.

或者甚至单击提交"按钮就足够了.

Or even on the click of the submit button would be sufficient.

推荐答案

不是棱角分明,但是为什么不使用HTML属性呢?Angular很喜欢这些,您可以检查表单的$ valid属性以确保满足约束条件.

Not angular, but why not use the HTML attributes? Angular is hip to these and you can check the $valid property of the form to make sure the constraints are satisfied.

<input type="number" min="0" max="24" step="1">

这篇关于Angular.JS-在输入数字字段中最多只允许一个特定的数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆