RadNumericTextBox - prevent input of decimal separator

3 posts, 0 answers
  1. JP
    JP avatar
    122 posts
    Member since:
    Aug 2011

    Posted 11 Sep 2013 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Sep 2013 Link to this post

    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.
  3. Gabriel
    Gabriel avatar
    5 posts
    Member since:
    Apr 2014

    Posted 16 Apr 2018 Link to this post

    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

Back to Top