Advertising sustains the DA. Ads are hidden for members. Join today

Contributed module documentation

Mask Field

The Mask Field module uses the jQuery Mask Plugin to enable adding masks to input fields. By masking the user input, the provided values are restricted to only the allowed formats. Examples of data that should be masked include phone numbers, ZIP codes and IP addresses.

Mask field offers:

  • Field widget settings to add masks to fields. Several Drupal's widget types are supported out-of-the-box (text field and telephone). Others can be easily added by third-party modules - by providing a my_module.mask_widget_types.yml file.
  • A Form API property ("#mask") to enable masking form elements in custom forms. The supported form elements include "textfield" and "tel". More can be easily added by third-party modules - with the help of the Drupal\mask\Helper\ElementHelper class.

Basic usage

How to mask your content's fields.

Form API

How to mask your custom form's fields.

Guide maintainers

dbiscalchin's picture