MaskedTextBox allow decimals at any position with maxlength

3 posts, 0 answers
  1. Ratno
    Ratno avatar
    2 posts
    Member since:
    Feb 2017

    Posted 17 Mar Link to this post

    Hi,

    I have a requirement where user can enter numbers with decimals with max length of 10 and the decimal point can occur anywhere within the input. Sample input can be like 1223.4588, 123456.78, 012.45, 678 etc

    Can i use the rules option of the maskedtextbox to achieve this. I guess the only option would be to use a regex pattern but it doesn't seem to work. We tried below and also k-mask="'00000.0000'" but none seem to work

    $("#id").kendoMaskedTextBox({
       mask: "{{^(?!0\d|\.|.*?\..*?\.)(?=(?:\.?\d){1,10}$)(.*)$}}"
    }); 

    For requirement above will the numerictextbox serve the purpose ?

  2. Stefan
    Admin
    Stefan avatar
    1131 posts

    Posted 20 Mar Link to this post

    Hello Ratno,

    Currently, the desired result is not supported out of the box from both widgets.

    For the NumericTextBox, I can suggest the following example demonstrating how to restrict the number of entered characters. Additional custom logic can be added, to check if a decimal point is present to changed the number of allowed characters plus one. Please have in mind that this will still not make the same result:

    http://jsfiddle.net/krustev/jZVas/

    https://www.w3schools.com/tags/att_input_maxlength.asp

    I can suggest submitting a feature request, to be able to set maxLenght on the widget which will consider the decimal part as well. Then based on its popularity we may implement it in a future release:

    http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/category/170304-numerictextbox

    Regards,
    Stefan
    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.
  3. Ratno
    Ratno avatar
    2 posts
    Member since:
    Feb 2017

    Posted 23 Mar in reply to Stefan Link to this post

    Thanks Stefan. Apparently the max length will not solve our purpose but we will consider submitting the feature request in the forums.

    To solve our issue we reverted back to using a normal HTML input element with a custom attribute and used a custom angular directive to check for the regex and the length together.

Back to Top