Masked Input Fields
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 Knockout.
You can add input masks to Single-Line Input questions and Multi-Select Matrix questions with cells of the "text"
cellType
. To configure an input mask, specify the question's maskType
and 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 |
"currency" |
InputMaskCurrency |
"datetime" |
InputMaskDateTime |
"pattern" |
InputMaskPattern |
Numeric Input Mask
A numeric input mask allows you to set minimum and maximum limits on a numeric value (the min
and max
properties), specify value precision
if the value is a fractional number, and define symbols to use as a decimalSeparator
and a thousandsSeparator
:
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
and/or a suffix
to the value:
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
property description for a full list of supported placeholders. Optionally, you can limit the date range using the min
and max
properties:
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
, you can use 9
for a digit, a
for a letter, #
for a digit or a letter, and \
to escape a character:
const surveyJson = {
"elements": [{
"name": "phone"
"type": "text",
"maskType": "pattern",
"maskSettings": {
"pattern": "+9(999)-999-99-99"
}
}]
}
You can also use the maskSettings.patternDefinitions
object in global 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
property within the maskSettings
object:
const surveyJson = {
"elements": [{
"name": "masked-field"
"type": "text",
"maskType": "numeric", // or "currency" | "datetime" | "pattern"
"maskSettings": {
// ...
"saveMaskedValue": true
}
}]
}