ExtJs 数字字段
我正在使用 ExtJs NumberField。好处是它可以验证只输入数字。 但我也想要一个连字符。我怎样才能编辑javascript
var <portlet:namespace/>issueNoField = new Ext.form.NumberField({ //This takes only numbers
fieldLabel: 'Issue No',
width: 120,
displayField: 'Enter no',
valueField:'IssNo'
});
I am using ExtJs NumberField. The good thing is it validates that only numbers are entered.
But I want a hyphen as well. How could I go about editing the javascript
var <portlet:namespace/>issueNoField = new Ext.form.NumberField({ //This takes only numbers
fieldLabel: 'Issue No',
width: 120,
displayField: 'Enter no',
valueField:'IssNo'
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
使用“baseChars”选项。
Use "baseChars" option.
尝试 Fiddle
最好使用文本字段并添加 maskRe 属性
maskRe: /^[0-9 -]$/
Try the Fiddle
Its better to use the textfield and adding the maskRe attribute as
maskRe: /^[0-9 -]$/
连字符仅仅是传统的,如美国邮政编码 (99999-9999) 中的连字符吗?在这种情况下,您应该只接受数字输入,在到达该位置时插入连字符,并忽略任何非数字字符。
如果连字符很重要,因此“12-345”和“123-45”是不同的输入,那么您正在阅读文本而不是数字。然而,这将是一个极其不友好的系统。
Is the hyphen merely conventional, as in a US zip code (99999-9999)? In that case, you should accept only numeric input, insert the hyphen when that position is reached, and ignore any non-numeric characters.
If they hyphen is significant, so that "12-345" and "123-45" are different inputs, then you are reading text and not a number. However, that would be an extremely unfriendly system.
Regex 属性对我来说从来不起作用,我使用了下面的代码:
The Regex attribute never worked for me, I used the code below instead:
我在这里建议的是,我们使用
文本字段
并为其添加一个掩码,以仅捕获所需格式的数值。您可以根据需要屏蔽它。
例如:
更多信息 这将以您想要的格式提供电话号码
What I'm proposing here is that we use a
text field
and put a mask to it to capture only numeric values in the desires format.You can mask it according to your needs.
For Example:
More info This will give the phone number in the format you want
只需将数字字段的
allowExponential
配置设置为 false 即可。默认情况下,它是 true 并添加'e+-'
和decimalSeparator
作为有效字符。这是真的。源码查一下源码。
Just set the
allowExponential
config of your numberfield to false. By default it is true and it adds'e+-'
and thedecimalSeparator
as valid characters.It's true. The source check the source.