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

RadNumericTextBox - prevent input of decimal separator

2 Answers 542 Views
Input
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 11 Sep 2013, 09:30 AM
Hello,

I want to use a RadNumericTextBox as input for integers. But there is still a problem: The user can still insert a decimal separator.
How can I prevent this?
This is the code:

textBox = new RadNumericTextBox();
textBox.ID = "NumTextBox";
textBox.Type = NumericType.Number;
textBox.DataType = typeof(int);
textBox.NumberFormat.DecimalDigits = 0;
textBox.ShowSpinButtons = true;

What else must I set?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Sep 2013, 10:39 AM
Hi JP,

Please have a look into the following JavaScript I tried which works fine at my end.

JavaScript:
<script type="text/javascript">
    function OnKeyPress(sender, args) {
        var keycode = args.get_keyCode()
        if (keycode == 46 || keycode == 110) {
            args.set_cancel(true);
        }
    }
</script>

Thanks,
Princy.
0
Gabriel
Top achievements
Rank 2
answered on 17 Apr 2018, 04:09 AM

Hi JP,

 

I believe you've solved this time ago, but maybe someone else gets in here, just to complete the answer if you want to get rid of the decimal separator you can use something like:

 

var txtQty = new RadNumericTextBox { ID = "txtQuantity", MinValue = 0, NumberFormat = { DecimalDigits = 0, GroupSeparator = "" } };

 

Best Regards,

Gabriel

Tags
Input
Asked by
JP
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gabriel
Top achievements
Rank 2
Share this question
or