You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gemes Tibor <ti...@i-trade.hu> on 2003/01/15 10:03:43 UTC

[validator] numbers with localized decimal separator

In hungarian language the decimal separator is comma:
123.45 would be written in the form of 123,45

Btw are you aware of any other Locale in which the decimal separator is not 
'.'? 

If the user enters number and the client's Locale is hu then the validateFloat 
cannot parse it. The float validator should take into account the Locale of 
the client, shouldn't it?

Tib

Ps: At the moment I have a workaround. In the default formset I use the 
float validator. In case of language="hu" I use a formset with the mask 
validator with the following mask: ^\d*(,\d*)?$




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Gemes Tibor <ti...@i-trade.hu>.
2003-01-15, sze keltezéssel Rod McChesney ezt írta:
> Sorry, I didn't understand that the javascript validation was
> the problem. It does seem like the Java validator code should
> be locale-sensitive, but that's a separate question.

both

> Since javascript number parsing does not handle locales, I guess
> one approach would be to treat everything as a regex mask
> instead of using the numeric validators, and include a
> hashtable mapping from locale to expected pattern. The script
> would look up the proper mask based on the locale. The locale
> would also have to be stuck into the javascript as a variable.
> I think that's similar to what you said, but would leave the
> number in its native state.

I was trying to say exactly the same but I failed. I think that most
locales has the '.' separator, so I think that it is enough if the
not-'.'-separator locales are stored in the script. 

Sorry for my weak english. 

Tib


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Rod McChesney <ro...@openwave.com>.
Sorry, I didn't understand that the javascript validation was
the problem. It does seem like the Java validator code should
be locale-sensitive, but that's a separate question.

Since javascript number parsing does not handle locales, I guess
one approach would be to treat everything as a regex mask
instead of using the numeric validators, and include a
hashtable mapping from locale to expected pattern. The script
would look up the proper mask based on the locale. The locale
would also have to be stuck into the javascript as a variable.
I think that's similar to what you said, but would leave the
number in its native state.

Or maybe I'm just missing something obvious...

Rod

Gemes Tibor wrote:
> I use NumberFormat extensively in converting the String into float. That
> is fine. Imho the problem is that the validation javascript is static. I
> don't know how to obtain the current Locale in the script.
> 
> Maybe I should not try to find it out via javascript but modify the
> validator framework to generate a string representation as a parameter
> to the validation function call. The validation script function would
> know somehow the exception locales to the '.' separators. If there is no
> other way then even in a constant map.
> 
> Any ideas?
> 
> Tib
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Gemes Tibor <ti...@i-trade.hu>.
2003-01-15, sze keltezéssel Rod McChesney ezt írta:
> This is deeper in the validation code, but I believe that
> java.text.DecimalFormat should be used for float
> or double parsing. Using Double d = new Double(string)
> the way GenericTypeValidator does will not work right in other locales.
> 
> The javadoc for class Double says this in the secion on the
> valueOf(String s) method:
> 
>    To interpret localized string representations of a
>    floating-point value, use subclasses of NumberFormat.

I use NumberFormat extensively in converting the String into float. That
is fine. Imho the problem is that the validation javascript is static. I
don't know how to obtain the current Locale in the script.

Maybe I should not try to find it out via javascript but modify the
validator framework to generate a string representation as a parameter
to the validation function call. The validation script function would
know somehow the exception locales to the '.' separators. If there is no
other way then even in a constant map.

Any ideas?

Tib


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Rod McChesney <ro...@openwave.com>.
This is deeper in the validation code, but I believe that
java.text.DecimalFormat should be used for float
or double parsing. Using Double d = new Double(string)
the way GenericTypeValidator does will not work right in other locales.

The javadoc for class Double says this in the secion on the
valueOf(String s) method:

   To interpret localized string representations of a
   floating-point value, use subclasses of NumberFormat.

HTH,

Rod

Gemes Tibor wrote:
> 2003. január 15. 10:42 dátummal Simon Kelly ezt írtad:
> 
> 
>>Btw are you aware of any other Locale in which the decimal separator is not
>>'.'?
>>
>>Germany uses the ',' as well.
> 
> 
> ok, so I assume this is a problem. 
> 
> Do you think that is there any other way of validating float number input but 
> masking it with the pattern  ^\d*(,\d*)?$  where the ',' should be replaced 
> with the localized decimal separator?
> 
> Tib
> 
> Oh, and this should parsed localized as well, and replaced each parseFloat 
> with this imho.
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Gemes Tibor <ti...@i-trade.hu>.
2003. január 15. 10:42 dátummal Simon Kelly ezt írtad:

> Btw are you aware of any other Locale in which the decimal separator is not
> '.'?
>
> Germany uses the ',' as well.

ok, so I assume this is a problem. 

Do you think that is there any other way of validating float number input but 
masking it with the pattern  ^\d*(,\d*)?$  where the ',' should be replaced 
with the localized decimal separator?

Tib

Oh, and this should parsed localized as well, and replaced each parseFloat 
with this imho.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [validator] numbers with localized decimal separator

Posted by Simon Kelly <ke...@ipe.fzk.de>.
----- Original Message -----
From: "Gemes Tibor" <ti...@i-trade.hu>

Btw are you aware of any other Locale in which the decimal separator is not
'.'?


Germany uses the ',' as well.

Simon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>