Masked Input

Sometimes you need the user to input data in a particular format like a Social Security Number or a standard US phone number. By masking input of a particular textbox, you can change its behavior so that it accepts input only according to specified format, e.g. a masked phone number input box will only allow 10 digits of of the phone number to pass through and won’t accept any other input.

This module provides the Masked Input Plugin by Josh Bush.

Drupal 8 users:

Currently this module only works with Field type
1) Text(Plain)
2) Text(Formatted)
3) Text(Formatted,long)

Drupal 7 users:

This module includes:

  • A fully configurable field widget
  • A form element
  • A small API for embedding this feature on existing form elements
  • A user interface for configuring your own mask definitions
  • Drush integration
  • Drush make example file

You are free to use this module in the same fashion that is described for the Drupal 6 version, all you'll need to do is include the script from code using Libraries API

libraries_get_path('maskedinput') . '/jquery.maskedinput-1.3.js';

Drupal 6 users:

There is a simple configuration page that allows you to enter each field you want masked along with simple masking parameters.

Use the following format: $("#YOUR-FIELD-ID").mask("YOUR-MASK");

Where "YOUR-FIELD-ID" is the CSS ID of the textfield you want to mask and "YOUR-MASK" is one of the following

  • a - Represents an alpha character (A-Z,a-z)
  • 9 - Represents a numeric character (0-9)
  • * - Represents an alphanumeric character (A-Z,a-z,0-9)

Examples:

$("#phone").mask("(999) 999-9999");

$("#tax-id").mask("99-9999999");

$("#ssn").mask("999-99-9999");

$("#prod-num").mask("a*-999-a999");

$("#pct").mask("99%");

Optionally, if you are not satisfied with the underscore ("_") character as a placeholder, you may pass an optional argument to the maskedinput method.

$("#YOUR-FIELD-ID").mask("99-999999",{placeholder:"+"});

Version 2.0 authored and maintained by Helior Colorado
Version 1.0 authored and maintained by Tim Wooten

Supporting organizations: 

Project Information

Downloads