Validation

The MaskedTextBox provides a set of predefined mask rules and enables you to modify them.

Predefined Masks

If no mask is defined, the widget allows any input.

The MaskedTextBox has a list of predefined mask rules which can be used to compose the mask of a widget.

The following example demonstrates how to set a zip code mask.

    @(Html.Kendo().MaskedTextBox()
          .Name("maskedtextbox")
          .Mask("00000-9999") // Set the zip code.
    )

Custom Masks

The MaskedTextBox enables you to define custom mask rules if none of the predefined ones is suitable. To add a custom rule, use the Rules method.

The widget supports JavaScript Regular Expressions defined as a string or a JavaScript function.

The following example demonstrates how to define a custom rule for the - (minus) and + (plus) symbols.

  @(Html.Kendo().MaskedTextBox()
        .Name("maskedtextbox")
        .Rules(rules => {
            rules.Add('~', "/[+-]/");
        })
        .Mask("~0000") // Set a mask with a custom rule.
   )

See Also

In this article
Not finding the help you need? Improve this article