有没有办法阻止 Mobile Safari 在 HTML 表单的数字字段中插入逗号?
我有一个网站,其中包含一个允许用户输入信用卡详细信息的表单。卡号、发行号、CVC 号以及希望存入的金额字段使用 HTML 表单中类型为“number”的输入框。
iOS 5 附带的更新版 Mobile Safari 会自动在“数字”输入字段中的数字中插入逗号。这不仅在 CC 号码中看起来很愚蠢,而且破坏了我的验证。有办法阻止这种情况吗?
使用“数字”而不是“文本”的唯一目的是让 iOS 和 Android 调出纯数字软键盘而不是完整键盘。
我尝试使用“文本”类型输入,并将模式设置为“[0-9]*”。这会在 iOS 上调出数字键盘,但在 Android 上不会调出。它还不允许输入带有小数点的数字。
如果有任何建议,我将不胜感激:)
谢谢
I've got a site that contains a form to allow users to enter credit card details. The fields for the card number, issue number, CVC number and the amount they wish to deposit use an input box in an HTML form with the type "number".
The updated Mobile Safari that comes with iOS 5 automatically inserts commas into numbers in "number" input fields. This not only looks stupid in a CC number, but it breaks my validation. Is there a way to stop this?
The only purpose of using "number" as opposed to "text" is to make iOS and Android bring up a numbers-only soft keyboard rather than the full keyboard.
I've tried using a "text" type input with a pattern set to "[0-9]*". This brings up the numbers keyboard on iOS but not on Android. It also doesn't allow the number to be entered with a decimal point.
I'd be very greatful for any suggestions :)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将其从“号码”更改为“电话”,但我没有再看到问题发生。
I changed mine from "number" to "tel" and I've not seen the issue occur anymore.
您已经很接近了 - 您所需要做的就是将模式设置为“[0-9]*”并将类型保留为“数字”。
You're close - all you need to do is set the pattern to "[0-9]*" and keep the type as "number".
我也有同样的问题。我认为这与您设置中的区域格式有关。您可以将类型设置为“文本”:
0 到 9999.99 之间的值。不过,此解决方案不会触发 iOS 5 上的数字键盘。
或者保留区域设置覆盖(点/逗号)并设置:
对于 0 到 9999.99 之间的十进制值。
此外,验证失败或清空属性为“required”的字段不会阻止表单在 Safari 5.1(OS X 和 iOS)中提交。
I'm having the same problem. I think it has to do with the region format in your settings. You can set type to "text":
for a value between 0 and 9999.99. This solution doesn't trigger the number keyboard on iOS 5, though.
Or keep the regional settings overwrite (dot/comma) and set:
for decimal values between 0 and 9999.99.
Also failure to validate or empty fields with attribute "required" are not preventing form from submitting in Safari 5.1 (OS X and iOS).