仅接受正数的Textfield -Javafx
我正在尝试在Javafx(使用场景构建器)中创建一个仅接受正数的TextField。
我实际上是为了制作一个“信用卡号”的文本字段,该文本字段接受13-16个数字值,而不包括开始时的减号,并且可以在文本开头接受0。
另外,由于这是一个“信用卡号” Textfield,我正在寻找一种可以在每4个字母/号码插入它之后插入自动空间的方式。
注意: 我知道如何创建一个仅接受数字的文本字段,但它在开始时也接受减号,并且不接受0作为第一个输入。
I'm trying to create a TextField in JavaFX (using Scene Builder) that accepts only positive numbers.
I'm trying actually to make a TextField for a 'Credit Card Number' which accepts 13 - 16 numeric values, not including the minus sign at the beginning, and which can accept 0 at the beginning of the text.
Also, since it's a 'Credit Card Number' TextField, I'm looking for a way where I can insert automatic space after each 4 letters/numbers inserted to it.
Note: I know how to create a TextField that accepts only numbers but it also accepts minus sign at the beginning and doesn't accept the 0 as the first input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我一直在使用的内容,所以我的Textfield仅接受数字,它的工作方式如下所示,
并且要设置字符限制,我使用此功能,
编辑:
显然,一个文本格式化是一个文本格式,因为您称之为的第二个将替换第一个,并且您的字段只能一次运行。因此,我进行了一个联合格式,如下所示:
Here is what I have been using so my TextField only accepts digits and it works like a charm as below,
And to set a character limit I use this,
Edit:
Apparently one cannot have both text formatters as the second one you call will replace the first and your field will only run with one at a time. So I made a joint formatter as follows: