gpt4 book ai didi

javascript - ExtJS 4.2 中欧洲货币输入的正则表达式

转载 作者:行者123 更新时间:2023-11-30 16:21:53 27 4
gpt4 key购买 nike

我有一个文本字段,用户可以在其中输入价格值。我必须将输入作为 0,00(没有小数点,只有一个逗号表示美分值)。所以用户可以输入以下内容

  • 123
  • 123,(我会在模糊事件中删除这个逗号)
  • 123,1
  • 123,11

所以我写了这个 RegExp:^\d+(,\d{0,2})?$ 并在 regexpal.com 上测试了它对于上述测试用例,它验证了所有这些。

现在当我在我的代码中使用它时

xtype:'textfield',
fieldLabel: 'Tiefbau(informativ)',
maskRe: /^\d+(,\d{0,2})?$/

并尝试输入值 123,12,它不允许我输入逗号,因为我发现 Textfield 将每个单独的字符与“maskRe”表达式进行比较。

我想要“一个或没有逗号”“没有小数点”谁能告诉我解决方案或指出我的错误?

最佳答案

为什么不使用派生自textfieldnumberfield组件呢?它是一个专门的数字输入字段,只允许输入数字输入。

当您查看 documentation 时你会发现它用逗号而不是点解决了你的问题 decimalSeparator 配置。

使用 minValuedecimalPrecision 配置,您应该有一个适合您需要的输入字段。

{
xtype: 'numberfield',
fieldLabel: 'Tiefbau(informativ)',

decimalSeparator: ',', // use comma instead of dot
minValue: 0, // prevents negative numbers
decimalPrecision: 2, // maximum precision to display after the decimal separator
allowExponential: false, // disallow exponential values ([e+-] chars not typable)

// Remove spinner buttons, and arrow key and mouse wheel listeners
hideTrigger: true,
keyNavEnabled: false,
mouseWheelEnabled: false
}

参见 fiddle .

关于javascript - ExtJS 4.2 中欧洲货币输入的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34615661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com