---
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 add a [`prefix`](/form-library/documentation/inputmaskcurrency#prefix) and/or a [`suffix`](/form-library/documentation/inputmaskcurrency#suffix) to the value:


```js
const surveyJson = {
  "elements": [{
    "name": "currency"
    "type": "text",
    "maskType": "currency",
    "maskSettings": {
      "min": 0,
      "max": 100,
      "precision": 1,
      "prefix": "$",
      "suffix": " USD"
    }
  }]
}
```

## 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 masks 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.

## 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
<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));
});

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

### `src/json.js`

```js
export const json = {
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "panel",
          "name": "panel1",
          "elements": [
            {
              "type": "text",
              "name": "date",
              "title": "Date and time:",
              "maskType": "datetime",
              "maskSettings": {
                "pattern": "mm/dd/yyyy HH:MM"
              }
            },
            {
              "type": "text",
              "name": "currency",
              "startWithNewLine": false,
              "title": "Currency:",
              "maskType": "currency",
              "maskSettings": {
                "prefix": "$"
              }
            },
            {
              "type": "text",
              "name": "decimal",
              "title": "Decimal:",
              "maskType": "numeric",
              "maskSettings": {
                "precision": 1
              }
            },
            {
              "type": "text",
              "name": "phone",
              "startWithNewLine": false,
              "title": "Phone:",
              "maskType": "pattern",
              "maskSettings": {
                "pattern": "+9(999)-999-99-99"
              }
            },
            {
              "type": "text",
              "name": "creditcard",
              "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)
