Get number of decimal places on keypress

2 posts, 0 answers
  1. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 24 Feb 2017 Link to this post

    We generate dynamic fields where the user can define their precision (total number of digits) and scale (number of digits to the right of the decimal).  We set max length based on precision + 1 for a negative and + 1 for the decimal such that if the user defined a field with precision 7 and scale of 3, the max length would be 9 (7 digits, 1 for potential and 1 for potential decimal).  (When the scale is 0, the max length is precision + 1 for potential negative).  We need to prevent users from entering more than the precision (e.g., the total number of digits) when entering values, regardless of whether the number is positive or negative as well as whether there's a decimal or not.  For example, if the precision is 5 and scale is 3, max length would be 7.  12345 would be valid, as would -12345 or -123.45.  However, 123456 or 12345.6 would not.

    I have the following wired up (and executing upon keypress), but in traversing the sender object, I am unable to get to the options (where I believe the scale is kept based on this page):

        format: "#.### \\%",
        checkNumericTextboxDecimals(this, null);
    function checkNumericTextboxDecimals(sender, args) {
        window.setTimeout(function () {
        var textBox = $(;


    With the above in mind, given a Kendo Numeric Textbox, how does one go about getting the scale via jQuery?  

    (Something similar to the above worked great when we had RadControls implemented, but isn't functional using Kendo controls.)

    Finally, why isn't this functionality supported within the control itself?  I find it hard to believe we're the only ones who see this as a shortcoming.

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 28 Feb 2017 Link to this post

    Hello Matt,

    The NumericTextBox exposes "decimals", "min", "max" and "factor" properties for limiting the input and I have to say that the requirement that you have is not common. Nevertheless, for performing your custom validation you bind a keydown event using jQuery directly:
    <input id="numerictextbox" />
        decimals: 1
      $("#numerictextbox").bind("keypress", function(){
        var numeric = $(this).data("kendoNumericTextBox");   

    Hope this helps.

    Konstantin Dikov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top