---
title: Masked Input Fields
product: Form Library
description: Make sure respondents correctly enter data by adding input masks for fields that require a certain data format, e.g., a field for a phone number, or an email address. View a free demo example for JavaScript to learn more.
framework: jQuery
source: https://surveyjs.io/form-library/examples/masked-input-fields/jquery
index: https://surveyjs.io/form-library/examples/overview.md
---

# Masked Input Fields (jQuery)

Your form may contain text fields whose values should have a specific format. To ensure that users enter values correctly, you can add input masks to these form fields. This demo shows how to specify different input mask types. Switch between available JavaScript frameworks to view a dedicated demo version of input masking for jQuery, React, Angular, Vue.js, or Vanilla JavaScript.

You can add input masks to [Single-Line Input](https://surveyjs.io/form-library/examples/text-entry-question/) questions and [Multi-Select Matrix](https://surveyjs.io/form-library/documentation/api-reference/matrix-table-with-dropdown-list) questions with cells of the `"text"` [`cellType`](https://surveyjs.io/form-library/documentation/api-reference/matrix-table-with-dropdown-list#cellType). To configure an input mask, specify the question's [`maskType`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#maskType) and [`maskSettings`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#maskSettings) properties. Supported mask types are listed in the table below. Each mask type has a corresponding class whose properties you can specify in the `maskSettings` object.

| `maskType` | Class |
| ---------- | ----- |
| `"numeric"` | [`InputMaskNumeric`](https://surveyjs.io/form-library/documentation/api-reference/inputmasknumeric) |
| `"currency"` | [`InputMaskCurrency`](https://surveyjs.io/form-library/documentation/api-reference/inputmaskcurrency) |
| `"datetime"` | [`InputMaskDateTime`](https://surveyjs.io/form-library/documentation/api-reference/inputmaskdatetime) |
| `"pattern"` | [`InputMaskPattern`](https://surveyjs.io/form-library/documentation/api-reference/inputmaskpattern) |

## Numeric Input Mask

A numeric input mask allows you to set minimum and maximum limits on a numeric value (the [`min`](/form-library/documentation/inputmasknumeric#min) and [`max`](/form-library/documentation/inputmasknumeric#max) properties), specify value [`precision`](/form-library/documentation/inputmasknumeric#precision) if the value is a fractional number, and define symbols to use as a [`decimalSeparator`](/form-library/documentation/inputmasknumeric#decimalSeparator) and a [`thousandsSeparator`](/form-library/documentation/inputmasknumeric#thousandsSeparator):

```js
const surveyJson = {
  "elements": [{
    "name": "number",
    "type": "text",
    "maskType": "numeric",
    "maskSettings": {
      "min": 0,
      "max": 100,
      "precision": 1,
      "decimalSeparator": ",",
      "thousandsSeparator": "."
    }
  }]
}
```

## Currency Input Mask

A currency input mask provides the same capabilities as a numeric input mask, plus it allows you to specify a [`currencySymbol`](/form-library/documentation/api-reference/inputmaskcurrency#currencySymbol) (for example, `"$"` or `"USD"`) and a [`currencyPattern`](/form-library/documentation/api-reference/inputmaskcurrency#currencyPattern) that controls the position of the number, currency symbol, and minus sign.

The `currencyPattern` property supports the following placeholders:

- `#` &mdash; The formatted number, including decimal and thousands separators. Required exactly once.
- `@` &mdash; *(Optional)* The currency symbol.
- `-` &mdash; *(Optional)* The minus sign for negative values. Omitted for positive values. If this placeholder is absent, the minus sign appears at the beginning of a negative value.

Other characters are displayed as literal text. Digits and control characters are not allowed. For example, the following configuration displays `12.3` as `12.3 USD`:

```js
const surveyJson = {
  "elements": [{
    "name": "currency",
    "type": "text",
    "maskType": "currency",
    "maskSettings": {
      "min": 0,
      "max": 100,
      "precision": 1,
      "currencySymbol": "USD",
      "currencyPattern": "# @"
    }
  }]
}
```

## Date and Time Input Mask

A date and time input mask specifies a pattern for a date time value. This pattern can include separator characters and placeholders that designate date and time components (month, day, year, hours, minutes, seconds). Refer to the [`pattern`](/form-library/documentation/inputmaskdatetime#pattern) property description for a full list of supported placeholders. Optionally, you can limit the date range using the [`min`](/form-library/documentation/inputmaskdatetime#min) and [`max`](/form-library/documentation/inputmaskdatetime#max) properties:

```js
const surveyJson = {
  "elements": [{
    "name": "date",
    "type": "text",
    "maskType": "datetime",
    "maskSettings": {
      "pattern": "mm/dd/yyyy",
      "min": "2024-03-01",
      "max": "2024-04-01"
    }
  }]
}
```

## Pattern Input Mask

A pattern input mask allows you to set a custom value format (phone number, email address, credit card number, etc.). Within the [`pattern`](/form-library/documentation/inputmaskpattern#pattern), you can use `9` for a digit, `a` for a letter, `#` for a digit or a letter, and `\` to escape a character:

```js
const surveyJson = {
  "elements": [{
    "name": "phone",
    "type": "text",
    "maskType": "pattern",
    "maskSettings": {
      "pattern": "+9(999)-999-99-99"
    }
  }]
}
```

You can also use the [`maskSettings.patternDefinitions`](/form-library/documentation/api-reference/settings#maskSettings) object in [global settings](/form-library/documentation/api-reference/settings) to define your own placeholder symbols and map them to custom regular expressions.

## Regional Format for Survey-Wide Customization

Previously described input masks apply to individual editors, but you can also define formats that apply throughout the whole survey.

By default, date-time, numeric, and currency masks use the formats for the survey's [`locale`](/form-library/documentation/api-reference/survey-data-model#locale). To change these formats without changing the survey's language, set [`regionalFormat.locale`](/form-library/documentation/api-reference/regionalformat#locale). For example, setting it to `"de"` selects German formats:

```js
const surveyJson = {
  "regionalFormat": {
    "locale": "de"
  },
  "elements": [{
    "name": "date",
    "type": "text",
    "maskType": "datetime"
  }, {
    "name": "currency",
    "type": "text",
    "maskType": "currency"
  }, {
    "name": "number",
    "type": "text",
    "maskType": "numeric"
  }]
}
```

You can customize the formats with these [`regionalFormat`](/form-library/documentation/api-reference/survey-data-model#regionalFormat) properties: [`datePattern`](/form-library/documentation/api-reference/regionalformat#datePattern), [`timePattern`](/form-library/documentation/api-reference/regionalformat#timePattern), [`decimalSeparator`](/form-library/documentation/api-reference/regionalformat#decimalSeparator), [`thousandsSeparator`](/form-library/documentation/api-reference/regionalformat#thousandsSeparator), [`currencySymbol`](/form-library/documentation/api-reference/regionalformat#currencySymbol), and [`currencyPattern`](/form-library/documentation/api-reference/regionalformat#currencyPattern).

For example, the following code places `USD` after each currency value unless an individual currency mask overrides these settings:

```js
survey.regionalFormat.currencySymbol = "USD";
survey.regionalFormat.currencyPattern = "# @";
```

In this demo, the region selector changes `survey.regionalFormat.locale`. The currency field, decimal field, and date-time field without a pattern then update to match the selected region. Other editors with defined patterns keep their individual settings.

## Store Masked Value in Survey Results

If you want to save the question value with an applied input mask, enable the question's [`saveMaskedValue`](/form-library/documentation/inputmasknumeric#saveMaskedValue) property within the `maskSettings` object:

```js
const surveyJson = {
  "elements": [{
    "name": "masked-field",
    "type": "text",
    "maskType": "numeric", // or "currency" | "datetime" | "pattern"
    "maskSettings": {
      // ...
      "saveMaskedValue": true
    }
  }]
}
```

## Files

### `public/index.html`

```html
<link href="https://fonts.googleapis.com/css?family=Open%20Sans:400,600&display=swap" rel="stylesheet">
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import $ from "jquery";
import { Model } from "survey-core";
import "survey-js-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

const survey = new Model(json);
survey.onComplete.add((sender, options) => {
    console.log(JSON.stringify(sender.data, null, 3));
});
survey.regionalFormat.locale = survey.getValue("region");
survey.onValueChanged.add((_, options) => {
  if (options.name === "region") {
    survey.regionalFormat.locale = options.value;
  }
});

$("#surveyElement").Survey({ model: survey });
```

### `src/json.js`

```js
export const json = {
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "dropdown",
          "name": "region",
          "title": "Region:",
          "titleLocation": "left",
          "defaultValue": "en-US",
          "allowClear": false,
          "choices": [
            { "value": "en-US", "text": "United States" },
            { "value": "en-GB", "text": "United Kingdom" },
            { "value": "de", "text": "Germany" },
            { "value": "fr", "text": "France" },
            { "value": "ja", "text": "Japan" }
          ]
        },
        {
          "type": "panel",
          "name": "panel1",
          "elements": [
            {
              "type": "text",
              "name": "dateWithoutPattern",
              "title": "Date and time (without pattern):",
              "maskType": "datetime"
            },
            {
              "type": "text",
              "name": "date",
              "title": "Date and time (with pattern):",
              "startWithNewLine": false,
              "maskType": "datetime",
              "maskSettings": {
                "pattern": "dd.mm.yyyy HH:MM"
              }
            },
            {
              "type": "text",
              "name": "currency",
              "title": "Currency:",
              "defaultValue": 1234.5,
              "maskType": "currency"
            },
            {
              "type": "text",
              "name": "decimal",
              "startWithNewLine": false,
              "title": "Decimal:",
              "defaultValue": 1234.5,
              "maskType": "numeric",
              "maskSettings": {
                "precision": 1
              }
            },
            {
              "type": "text",
              "name": "phone",
              "title": "Phone:",
              "maskType": "pattern",
              "maskSettings": {
                "pattern": "+9(999)-999-99-99",
                "saveMaskedValue": true
              }
            },
            {
              "type": "text",
              "name": "creditcard",
              "startWithNewLine": false,
              "title": "Credit card number:",
              "maskType": "pattern",
              "maskSettings": {
                "pattern": "9999 9999 9999 9999"
              }
            }
          ]
        }
      ]
    }
  ],
  "widthMode": "static",
  "width": "750px"
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "jquery": "latest",
    "survey-core": "latest",
    "survey-js-ui": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/masked-input-fields/angular.md)
- [React](https://surveyjs.io/form-library/examples/masked-input-fields/reactjs.md)
- [Vue 3](https://surveyjs.io/form-library/examples/masked-input-fields/vue3js.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/masked-input-fields/vanillajs.md)
