Prisoner ZERO
Prisoner ZERO

Reputation: 14176

Applying Regular Expressions in a Kendo MaskedTextBox

I want to globally assign a REGULAR EXPRESSION to a Kendo MaskedTextBox using JavaScript...but cannot get Kendo to 'recognize' the pattern(s).

...everything I have tried fails.

SAMPLE PATTERNS:
Some examples of things I might use include things like...

I want to do "something" like...

$('#txtMeterNumber').kendoMaskedTextBox({
    mask: "basicText",
    rules: {
        "basicText": /^[a-zA-Z0-9,.- ]*$/
    }
});

Upvotes: 0

Views: 4407

Answers (1)

Eduardo Castro
Eduardo Castro

Reputation: 48

You should use only one character to define the expression inside the "rules" object. Each character inside the mask property represents a single character in the actual input.

There are some examples in the docs.

Probably this is what you want:

$(document).ready(function(){
  $('#txtMeterNumber').kendoMaskedTextBox({
    mask: 'xxx-xxx-xxx',
    rules: {
      'x': /[a-zA-Z0-9- ]/
    }
  });
});
<script src="https://kendo.cdn.telerik.com/2014.2.716/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2014.2.716/js/kendo.ui.core.min.js"></script>
<input id="txtMeterNumber">


Basic Text: ^[a-zA-Z0-9,.- ]*$

This expression is incorrect, you have to scape the -. I think [a-zA-Z0-9,.\- ] will do the trick. You can check it at https://regexr.com/

Upvotes: 1

Related Questions