0

I want to apply validation if -ve value is entered. I could do that using below tags and attributes:

<h:inputText id="MyPrice" validatorMessage="negatieve prijs niet toegestaan">

    <f:convertNumber type="number"
                     groupingUsed="true"
                     locale="nl_NL"
                     maxFractionDigits="2"
                     minFractionDigits="2"/>

    <f:validateLongRange minimum="0"/>
<h:inputText>

<rich:message for="MyPrice"/>

Using this I can successfully validate -ve and +ve values with below inputs: Went right for: [I'm following Netherlands number system where ',' is treated as '.' eg to write 0.55 we need to write 0,55) that is done by me using <f:convertNumber>.

100
10.25
10,98
-100
-10.25
-10,98
0.55

But when I entered -0,55, validation didn't work. Kindly provide solution to validate when I'm entering -ve value that starts with -0.xx.

Tiny
  • 27,221
  • 105
  • 339
  • 599
  • Have you checked here? http://stackoverflow.com/questions/19765009/does-fconvertnumber-use-the-right-number-separator-when-using-patterns-to-for/ – pleft Feb 29 '16 at 15:31

1 Answers1

1

Your validator is not correct - price is not Long. Change it to

<f:validateDoubleRange minimum="0" />
Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
  • Again, I've one concern. – Sumit Gavhankar Mar 01 '16 at 13:04
  • When I enter -11 or -0.54 or -0,54 it works and validates as negative. Also when I enter abc00, it validates it as 'abc00' is not a number. But when i enter 00abc, it accept/makes it as 00,00. I want to show validation message for inputs like 00abc that "It is not a valid number". i.e. I want to show validation message if my input contains alphas. i cant use Validateregex as it fails my negative number validation. Please suggest. – Sumit Gavhankar Mar 01 '16 at 13:24
  • You can change from `f:convertNumber` to `` or ` – Vasil Lukach Mar 01 '16 at 14:40
  • Vasil, I guess changing to convertNumber would miss NL number system conversion. I tried doing it but failed. Is there any other attribute for inputText or f:validateDoubleRange that will avoid entering me 0abc kind of inputs. – Sumit Gavhankar Mar 01 '16 at 15:08
  • Did you try second option ``? – Vasil Lukach Mar 01 '16 at 16:11
  • I ll try checking out second option. Is there any attribute that will restrict alpha numeric entries and force us to enter only numbers provided that It would allow - and , characters. Validateregex is found useless as I m using validatedoublerange tag. Please suggest. – Sumit Gavhankar Mar 01 '16 at 20:00
  • You should use it with `` – Vasil Lukach Mar 01 '16 at 20:57
  • If I use converter instead of convertNumber, my Local=NL will be removed. I want to preserve that also. – Sumit Gavhankar Mar 01 '16 at 21:01
  • Move locale setup to view level: `` – Vasil Lukach Mar 03 '16 at 15:36