---
title: Inputmask
product: Form Library
description: Inputmask | JS Survey and Form Library Example for JavaScript
framework: React
source: https://surveyjs.io/form-library/examples/control-data-entry-formats-with-input-masks/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Inputmask (React)

## 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/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";
import * as SurveyCore from "survey-core";
import Inputmask from "inputmask";
import { inputmask } from "surveyjs-widgets";

inputmask(SurveyCore);
function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

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

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
   "elements": [
      {
         "type": "html",
         "name": "obsoleteMsg",
         "html": "<p>This example is obsolete. SurveyJS Form Library now offers the functionality of Inputmask out of the box. Please refer to the following example instead: <a href='https://surveyjs.io/form-library/examples/masked-input-fields/'>Masked Input Fields</a>.<p>"
      },
      {
         "name": "date",
         "type": "text",
         "title": "Date:",
         "inputMask": "datetime",
         "inputFormat": "mm/dd/yyyy"
      },
      {
         "name": "currency",
         "type": "text",
         "title": "Currency:",
         "inputMask": "currency",
         "prefix": "$",
         "numericDigits": 2,
         "startWithNewLine": false
      },
      {
         "name": "decimal",
         "type": "text",
         "title": "Decimal:",
         "inputMask": "decimal"
      },
      {
         "name": "phone",
         "type": "text",
         "title": "Phone:",
         "inputMask": "phone",
         "inputFormat": "+9(999)-999-99-99",
         "startWithNewLine": false
      },
      {
         "name": "ip",
         "type": "text",
         "title": "IP address:",
         "inputMask": "ip"
      },
      {
         "name": "email",
         "type": "text",
         "title": "Email address:",
         "inputMask": "email",
         "startWithNewLine": false
      }, {
         "name": "creditcard",
         "type": "text",
         "title": "Custom format",
         "description": "Enter a credit card number",
         "inputFormat": "9999 9999 9999 9999"
      }
   ],
   "questionTitleLocation": "left"
};
```

### `src/theme.js`

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

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "inputmask": "5.0.3",
    "surveyjs-widgets": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/control-data-entry-formats-with-input-masks/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/control-data-entry-formats-with-input-masks/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/control-data-entry-formats-with-input-masks/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/control-data-entry-formats-with-input-masks/vanillajs.md)
