This is a migrated thread and some comments may be shown as answers.

MaskedTextBox Custom Rules

2 Answers 149 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 15 May 2020, 02:39 PM

I'm looking to add custom rules to a masked textbox and there is not enough documentation or examples to explain how this works properly.

 

$(this).kendoMaskedTextBox({

    mask: "mm/dd",

rules: {

mm: "any number between 01 - 12",

dd: "any number between 01 - 31"}})

 

I attempted to use a masked date picker, but it still allows for entries like "48/99" which is incorrect.

 

Is it possible to do something like this using custom rules and regex?

 

2 Answers, 1 is accepted

Sort by
0
Patrick
Top achievements
Rank 1
answered on 15 May 2020, 03:07 PM

I found something... but I feel like there should be something easier:

 

$(this).kendoMaskedTextBox({
    mask: "mM/dD",
    rules: {
        "m": /[0-1]/,
        "M": /[0-9]/,
        "d": /[1-3]/,
        "D": /[0-9]/
    }
})
0
Nikolay
Telerik team
answered on 19 May 2020, 11:52 AM

Hello Patrick,

 The MaskedTextBox supports custom rules which allows you to determine whether the current char is valid or not using custom logic. The rules can be defined as a regular expression or a function. This is documented in the following article:

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
MaskedTextBox
Asked by
Patrick
Top achievements
Rank 1
Answers by
Patrick
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or