使用 p inputMask 后无法接受输入数字,为大于 999 的数字添加逗号

sur*_*dan 1 validation jsf primefaces input-mask

对于下面的输入文本字段,用户可以输入 1 到 99,999 之间的值。只输入数字。

<p:message for="usage" display="text"><p:autoUpdate/></p:message>
<p:inputText id="usage" maxlength="10" required="true"
    requiredMessage="You must provide an input" value="#{powerMB.usage}">  
    <f:validateDoubleRange minimum="1" maximum="99999" for="usage" />   
    <p:keyFilter regEx="/[0-9]/i"  />         
</p:inputText>
Run Code Online (Sandbox Code Playgroud)

当前输入值接受 - 示例

1 
34                      
99
3534
53535
Run Code Online (Sandbox Code Playgroud)

我曾试图掩盖一个特定的输入值

如何将 Primefaces inputMask 限制为仅数字?

https://www.primefaces.org/showcase/ui/input/inputMask.xhtml

试图为大于 999 的数字添加逗号

我收到以下代码的以下错误

usage: Validation Error: Value is not of the correct type
Run Code Online (Sandbox Code Playgroud)
<p:message for="usage" display="text"><p:autoUpdate/></p:message>
<p:inputMask id="usage" maxlength="5" required="true"
    requiredMessage="You must provide an input" mask="99,999" value="#{powerMB.usage}">  
    <f:validateDoubleRange minimum="1" maximum="99999" for="usage" />   
</p:inputMask>
Run Code Online (Sandbox Code Playgroud)

输入给定为

1       fail validation error
34      fail                
99      fail
3534    fail
53535   fail


00,001      fail validation error
00,034      fail                
00,099      fail
03,534  fail
053,535 fail

Run Code Online (Sandbox Code Playgroud)

使用 inputMask 后无法接受输入值

如果需要,可以提供现有功能的完整工作代码。

Kuk*_*tje 5

这不是对您的要求的答案,而是对您为什么会看到所看到的行为的解释。

你所有的失败都很容易解释...

逗号是必需的,所以所有这些都理所当然地失败了

1       fail validation error
34      fail                
99      fail
3534    fail
53535   fail
Run Code Online (Sandbox Code Playgroud)

其次你的 maxLength 是 5 所以所有这些都理所当然地失败了,因为长度是 6

00,001      fail validation error
00,034      fail                
00,099      fail
03,534      fail
Run Code Online (Sandbox Code Playgroud)

由于多种原因,这失败了

053,535     fail
Run Code Online (Sandbox Code Playgroud)

贪吃鬼

为了使逗号可选寻找更好的匹配模式。这对我来说超出了我想投入的努力。