HTML5输入标签中的格式编号 [英] Format number in an HTML5 input tag

查看:136
本文介绍了HTML5输入标签中的格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的输入

<input type="number" id="inputNumbers" step="0.01" ></input>

是否可以仅允许用户输入与模式"0.00"匹配的数字,就像我在step属性中声明的方式一样,而无需使用JavaScript?

Is it possible to only allow users to enter numbers that match the pattern '0.00', like the way I declare it in the step attribute, without using JavaScript?

示例:如果用户键入"1.23",然后尝试输入新的数字,小数或逗号,则不能,数字保持在"1.23".

Example: If the user types '1.23' and then tries to enter a new number, decimal or comma it can't and the number stays at '1.23'.

如果没有办法匹配step属性,是否有可能只允许小数点后一位?

If there's not a way to match the step attribute, Is it possible to only allow one decimal in the number?

推荐答案

我认为您可以尝试执行以下操作:

I think you can try something like this:

input type="number" name="number" pattern="([0-9]{1,3}).([0-9]{1,3})" title="Must contain a decimal number">

请参见此处

添加了Plunkr: 柱塞

Added Plunkr: Plunker

这篇关于HTML5输入标签中的格式编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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