Reputation: 23
For the input text field below, User can enter the values between one and 99,999. Enter only numbers.
<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>
Current Input values accept - examples
1
34
99
3534
53535
I have tried to mask a specific input values as per
How to restrict Primefaces inputMask to numbers only?
https://www.primefaces.org/showcase/ui/input/inputMask.xhtml
Tried to add a comma for numbers more than 999
I receive the following error for the code below
usage: Validation Error: Value is not of the correct type
<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>
Input Given as
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
unable to accept input values after I use inputMask
Can provide a full working code of the existing functionality if needed.
Upvotes: 1
Views: 778
Reputation: 12337
This is not the answer to your requirement but it is an explanation on why you see the behaviour you see.
All your failures are easily explained...
The comma is required so all these rightfully fail
1 fail validation error
34 fail
99 fail
3534 fail
53535 fail
Secondly your maxLength is 5 so all these rightfully fail since the length is 6
00,001 fail validation error
00,034 fail
00,099 fail
03,534 fail
And this fails for a combination of reasons
053,535 fail
SNAFU
To make the comma optional look for better matching patterns. It is for me beyond the effort I want to put in this.
Upvotes: 5