RadNumericTextbox automatically changes users input (without alert) when restricting users from entering decimal points and negative numbers

2 posts, 0 answers
  1. David
    David avatar
    13 posts
    Member since:
    Sep 2012

    Posted 24 Jun 2014 Link to this post

    I set the MinValue to 1 and the DecimalDigits to zero as shown below.

    <telerik:RadNumericTextBox ID="MyRadNumericTextBox"
        Culture="English (United States)"
        MinValue="1" >
        <NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>

    Steps to Reproduce
    Add the above RadNumericTextBox to a Webform.
    Enter a negative number. When the RadNumericTextbox loses focus, the value entered automatically changes to the value set as MinValue.
    Enter a number containing a decimal. When the RadNumericTextbox  loses focus, the value entered is automatically rounded to the nearest integer.

    I did find the following java snippets in your forum that are suppose to block the user from entering decimals and negative symbols  but neither of them work on both IE and FireFox. 

    Delete key does not work in FireFox

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

    The following was posted as a solution to work with both FireFox and IE but I can't get it to work on either
    <script type="text/javascript">
        function OnKeyPress(sender, args) {
            var keyCharCode = args.get_domEvent().rawEvent.charCode;
            if (keyCharCode == sender.get_numberFormat().DecimalSeparator.charCodeAt() || keyCharCode == sender.get_numberFormat().NegativeSign.charCodeAt()) {

    I would like to find a solution to this, but in the mean time I am swapping the RadNumericTextBox for the RadMaskedTextBox.

  2. Viktor Tachev
    Viktor Tachev avatar
    1789 posts

    Posted 27 Jun 2014 Link to this post

    Hello David,

    If you would like to prevent the values from being automatically corrected you need to set the AllowOutOfRangeAutoCorrect property to false. This way if the user enters an invalid value an invalid style will be applied to the input and the value is kept.

    Regarding your second query, if you would like to prevent the user from entering negative sign and decimal separator you could try the following handler for the OnKeyPress client event:

    function keyPress(sender, args) {
        var keyCharCode = args.get_domEvent().rawEvent.keyCode;
        if (keyCharCode == sender.get_numberFormat().DecimalSeparator.charCodeAt() || keyCharCode == sender.get_numberFormat().NegativeSign.charCodeAt()) {

    For your convenience I am attaching a sample project where the approach is illustrated.

    Viktor Tachev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top