javascriptkendo-uikendonumerictextbox

Show error when user types decimal character in KendoNumericTextbox


Using KendoUI for jQuery.

A new requirement has lead us to changing a KendoNumericTextbox from it's default settings to show only the integer value, as well as, alert the user in case they tried to input the decimal character. I see that Kendo shows a (!) element for a brief second when a user inputs a decimal character currently, but we need something that notifies them that decimals aren't allowed.

Currently validation checks if the input ranges from 0 to 100 with format: n0 and decimals: 0.


Solution

  • Since you are using kendo for jquery. You can just access it like a normal input and check if the user is typing in a decimal.. I wrote some code for you to try. This is from the kendo example on NumericTextBox.

    $( "#currency" ).keyup(function() {
         if ($(this).val().indexOf('.')!=-1)
         {
         alert('don't type decimals')
         }  
         });
    

    And the link to the kendo dojo where I edited the code for the first textbox. Hope this is helpful

    https://dojo.telerik.com/OXiBEKIw/2