This is a migrated thread and some comments may be shown as answers.

NumericUpDown allows to enter commas

5 Answers 283 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 17 May 2013, 05:25 PM
<telerik:RadNumericUpDown Value="{Binding DaysNumber}" Minimum="1" IsInteger="True" VerticalAlignment="Center" Margin="5" Maximum="999">
    <telerik:RadNumericUpDown.NumberFormatInfo>
        <globalization:NumberFormatInfo NumberGroupSeparator="" NumberDecimalSeparator="." />
    </telerik:RadNumericUpDown.NumberFormatInfo>
</telerik:RadNumericUpDown>

NumericUpDown control allows to enter commas (the screenshot is  attached). How can I forbid that?

5 Answers, 1 is accepted

Sort by
0
Anton
Top achievements
Rank 1
answered on 17 May 2013, 08:33 PM
I mean, how to do that properly without handling events. Now it looks like a defect in the control.
0
Accepted
Vladi
Telerik team
answered on 22 May 2013, 01:44 PM
Hello Anton,

Thank you for contacting us.

By design in the RadNumericUpDown control when the controls IsInteger property is set to true the control allows the typing of separators but when the value is parsed via lost focus or enter keyboard key press the value is parsed correctly to integer. After investigating the issue however we found a bug that causes the NumberDecimalSeparator to not be used if the other (CurrencyDecimalSeparator, PercentDecimalSeparator) are not set to the same separator. We logged the issue in our Public Issue Tracker System where you can track its status. As a workaround for this issue all you need to do is set those properties in the NumberFormatInfo, also if you don't want the comma and dot symbols to be allowed you could simply set the separators to a symbol that is less likely to be pressed like the "â„¢" symbol. The next code snippet shows the described approach:
<telerik:RadNumericUpDown VerticalAlignment="Center" HorizontalAlignment="Center"
                            SmallChange="0.1" IsInteger="True"
                            Minimum="1"  Margin="5" Maximum="99999">
    <telerik:RadNumericUpDown.NumberFormatInfo>
        <globalization:NumberFormatInfo NumberDecimalSeparator="â„¢" CurrencyDecimalSeparator="â„¢" PercentDecimalSeparator="â„¢"
                                        NumberGroupSeparator="" CurrencyGroupSeparator="" PercentGroupSeparator=""/>
    </telerik:RadNumericUpDown.NumberFormatInfo>
</telerik:RadNumericUpDown>
Hope this is helpful.

I updated your Telerik points for bringing this to our attention, if you have any other questions feel free to write to us again.

Regards,
Vladi
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anton
Top achievements
Rank 1
answered on 18 Jun 2013, 08:25 PM
Thank you, Vladi!
0
Koen
Top achievements
Rank 1
answered on 28 Jun 2013, 06:51 AM
To make some sense out of this behavior:

The RadNumericUpDown parses the text as follows:


double.TryParse(text, NumberStyles.Any, formatInfo, out parsedValue);

It uses "NumberStyles.Any", which inspects the formatInfo.

Like Vladi mentioned, if your formatInfo does not contain information on "CurrencyDecimalSeparator" and "CurrencyGroupSeparator", CurrencyGroupSeparator will default to comma.
That's why the parsing, and thus the control, will still accept commas.

The issue is in the parsing using "NumberStyles.Any".
It should take into account the "ValueFormat" property of the RadNumericUpDown, and use 
"NumberStyles.Number", "NumberStyles.Currency" accordingly in the parsing.


Regards,
Koen
0
Koen
Top achievements
Rank 1
answered on 28 Jun 2013, 06:53 AM
To make some sense out of this behavior:

The RadNumericUpDown parses the text as follows:


double.TryParse(text, NumberStyles.Any, formatInfo, out parsedValue);

It uses "NumberStyles.Any", which inspects the formatInfo.

Like Vladi mentioned, if your formatInfo does not contain information on "CurrencyDecimalSeparator" and "CurrencyGroupSeparator", CurrencyGroupSeparator will default to comma.
That's why the parsing, and thus the control, will still accept commas.

The issue is in the parsing using "NumberStyles.Any".
It should take into account the "ValueFormat" property of the RadNumericUpDown, and use 
"NumberStyles.Number", "NumberStyles.Currency" accordingly in the parsing.


Regards,
Koen
Tags
NumericUpDown
Asked by
Anton
Top achievements
Rank 1
Answers by
Anton
Top achievements
Rank 1
Vladi
Telerik team
Koen
Top achievements
Rank 1
Share this question
or