javascript - 接受值 100 及以上的文本框

标签 javascript jquery html validation

这是我的文本框:

textbox

这是它的代码:

        <!-- Preferred credit limit --> 
        <div class="signup-card-section">
            <h2 class="accordion-header boldtext">Tell Us Your Preferred Credit Limit</h2>
            <div class="column-control no-padding twelve colgrid">
                <fieldset>
                    <div class="row">
                        <p class="text-red">(Choose one)</p>
                        <p>My Preferred Credit Limit<span class="text-red">*</span></p>
                        <br>
                        <input type="radio" name="prefcreditlimit" checked="checked" value="yesprefcreditlimit" id="yesprefcreditlimit"> 
                        <span class="radiotextdeco">S$</span> <input type="text" class="input numeric-only nodecimal width30" name="prefcreditlimitval" id="prefcreditlimit" min="100"> <span style="font-size:12px;"> (Must be in multiples of 00’ and a minimum of S$100)</span><br><br>
                        <input type="radio" name="prefcreditlimit" checked="checked" value="noprefcreditlimit"> <span class="radiotextdeco">I dont have a preferred credit limit and agree to any credit limit determined</span><br><br>
                        <p><strong>Note:</strong> Principal applicant and Suplementary applicant will be granted the preferred credit limit of any limit determined by the bank, whichever is lower.</p>
                    </div>
                </fieldset>
            </div>
        </div>

如果输入的值不是 00 的倍数或最低 100 新元,则会出现错误消息:“您的首选信用额度必须是 00 的倍数和最低 100 新元。 因为我将最小值设置为 100。当用户输入小于 100 时会出现一条错误消息。现在的问题是,我不确定如何检查 00 的验证

如有任何帮助,我们将不胜感激。

最佳答案

使用 <input type="number">连同 minstep属性:

<input type="number" name="prefcreditlimitval" min="100" step="100">

如果用户输入的值小于最小值或不是步长的倍数,浏览器的验证将阻止提交表单。在不支持验证的浏览器中,您可以使用 polyfill(如 this one )。

您可以测试验证(尽管 SO 不允许运行表单):

input:invalid {
    border-color: red;
}
Input multiples of 100<br><br>
<input type="number" name="test" min="100" step="100">

关于javascript - 接受值 100 及以上的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38761470/

相关文章:

javascript - 在应用程序配置 angular.js 的自定义提供程序中使用 $http

JavaScript 异步函数流程

javascript - 将 JavaScript 函数放入对象中并在需要时调用它们有什么优点或缺点?

javascript - 显示/隐藏 Div 组合 jQuery

javascript - 为什么这个 URL 参数没有用 jQuery 隐藏这个 div?

html - Selenium 单击不起作用,但鼠标可以

javascript - Angular获取动态生成的html元素的值

javascript - 将 slider 添加到博客文章?

javascript - 如何使用一个输入链接表单并使用两个链接提交

Python从html中提取斜体内容