0

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

  • Q: How do you use Regex in a Kendo MaskedTextBox?

...everything I have tried fails.

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

  • Basic Text: ^[a-zA-Z0-9,.- ]*$
  • Unformatted Serial Numbers: ^[a-zA-Z0-9- ]*$

I want to do "something" like...

$('#txtMeterNumber').kendoMaskedTextBox({
    mask: "basicText",
    rules: {
        "basicText": /^[a-zA-Z0-9,.- ]*$/
    }
});
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137

1 Answers1

1

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/

  • I went ahead and marked this as the answer. However, using 'mask' in this manner limit's the number of characters in an undesired way. If possible, can you show an example where the max-length is, say, 25 characters, as well? – Prisoner ZERO Sep 29 '17 at 18:43
  • ...and, hopefully, doing so without putting 25 'x' values in the mask :-) – Prisoner ZERO Sep 29 '17 at 18:44
  • 1
    I guess this isn't the mask intent. Doing a quick search I found this: http://docs.telerik.com/kendo-ui/api/javascript/ui/validator. I believe this validator will best suit your needs. Hope it can helps. – Eduardo Castro Sep 29 '17 at 20:56