HTML5输入数字最小值不能使用所需

时间:2022-09-27 10:22:19

I would like to force the user to type their age. I also would like to make sure they only enter between 18-99. Is that possible with HTML5 attributes like required, pattern, min and max? Seems like it is not working

我想强迫用户输入他们的年龄。我也想确保他们只在18-99之间进入。是否可以使用HTML5属性,如required,pattern,min和max?好像它不起作用

<form>
    <input type="number" name="Q2age" id="Q2age" size="10" min="18" max="99" pattern="[1-8][0-9]" required>
    <button type="submit" class="button" id="test">Submit</button>
</form>

Am I doing something wrong here? I use Firefox 22.0 on Ubuntu 12.0.4LTS (tested on Chrome as well, but doesn't work.) Thank you for your help.

我在这里做错了吗?我在Ubuntu 12.0.4LTS上使用Firefox 22.0(在Chrome上测试过,但不起作用。)感谢您的帮助。

3 个解决方案

#1


7  

This is the expected behaviour because FF21 doesnt supports min,max attribute...

这是预期的行为,因为FF21不支持min,max属性......

you can check it in http://html5test.com/

你可以在http://html5test.com/查看

Check the screenshot HTML5输入数字最小值不能使用所需

检查屏幕截图

#2


4  

Your code works fine. Check this fiddle (I'm using latest chrome)

你的代码运行正常。检查这个小提琴(我使用最新的铬)

My only concern you is your pattern="[1-8][0-9]" can simple use this

我唯一担心的是你的模式=“[1-8] [0-9]”可以简单地使用它

pattern="[0-9]{2}"

#3


3  

It doesn't work in Firefox but it works in Chrome, Internet Explorer, Safari and Opera.

它在Firefox中不起作用,但适用于Chrome,Internet Explorer,Safari和Opera。

Please find the working demo here: Demo

请在这里找到工作演示:演示

<form action="">

<input type="number" name="points" min="1" max="10" name="Q2age" id="Q2age" required>

 <input type="submit" value="submit" />
</form>

#1


7  

This is the expected behaviour because FF21 doesnt supports min,max attribute...

这是预期的行为,因为FF21不支持min,max属性......

you can check it in http://html5test.com/

你可以在http://html5test.com/查看

Check the screenshot HTML5输入数字最小值不能使用所需

检查屏幕截图

#2


4  

Your code works fine. Check this fiddle (I'm using latest chrome)

你的代码运行正常。检查这个小提琴(我使用最新的铬)

My only concern you is your pattern="[1-8][0-9]" can simple use this

我唯一担心的是你的模式=“[1-8] [0-9]”可以简单地使用它

pattern="[0-9]{2}"

#3


3  

It doesn't work in Firefox but it works in Chrome, Internet Explorer, Safari and Opera.

它在Firefox中不起作用,但适用于Chrome,Internet Explorer,Safari和Opera。

Please find the working demo here: Demo

请在这里找到工作演示:演示

<form action="">

<input type="number" name="points" min="1" max="10" name="Q2age" id="Q2age" required>

 <input type="submit" value="submit" />
</form>