The datatype
tag validates respondent input to open-ended questions. An invalid response causes an error message to be displayed, prompting the respondent to provide an answer matching the specified datatype format.
Try it!
Details
- Datatypes modify or restrict which response types can be entered. Most input types are intended for use with text questions, and any numeric datatypes can also be used on either number or integer questions and tables. All date-related datatypes must be used with date questions.
- Most datatypes have a default text field size, and many have a built-in max response length. Include the
size
andmaxlength
tags to override the default sizing as needed. - The 'phone' datatype's max length allows for multiple input formats including '8008675309', '(800) 867-5309', or '800-867-5309'.
- Both the 'phone' and 'email' datatypes are encrypted by default. To encrypt other datatypes, add
encrypt: y
to the question.
Tip! The message displayed when a datatype
validation error is triggered can be customized. See message tags for additional information.
Accepted datatypes
The following parameters can be used as inputs for the datatype
tag.
Parameter (input) | Valid with | Description |
capostcode |
type: text |
Canadian postcode. Accepts the following format: A9A 9A9. |
date_ddmmyy |
type: date |
Requires date to be in DD/MM/YY format. |
date_ddmmyyyy |
type: date |
Requires date to be in DD/MM/YYYY format. |
date_mmddyy |
type: date |
Requires date to be in MM/DD/YY format. |
date_mmddyyyy |
type: date |
Requires date to be in MM/DD/YYYY format. This is the default datatype for |
(alias |
type: text , type: integer , type: number
|
A number with decimal places. Examples of acceptable inputs include:
|
email |
type: text |
Standard e-mail address with '@' and '.' separators (e.g., local@somedomain.com). Specifying this datatype only ensures that a properly formatted email address is accepted. Questions with this datatype are encrypted by default. |
integer |
type: text , type: number
|
A positive or negative whole number, including 0. Consider using |
number |
type: text , type: integer
|
A positive or negative integer, decimal, and 0. Consider using |
phone |
type: text , type: integer , type: number
|
Most often used for ten-digit phone numbers, e.g., 8005551234, 800-555-1234, 800.555.1234, (800)555-1234, (800) 555-1234, etc. Five-digit (some texting) and seven-digit (phone number without area code) can also be entered. See below for an example on how to ensure a ten-digit number is entered. Questions with this datatype are encrypted by default |
ukpostcode |
type: text |
United Kingdom postcode. Accepts the following formats: AA9A 9AA, A9A 9AA, A9 9AA, A99 9AA, AA9 9AA, AA99 9AA. Caution! This forces the respondent to enter a full postcode, which is considered PII (personally identifiable information) in the UK. See below for additional information. |
usstatecode |
type: text |
Two-letter United States state code, e.g., CA for California, KY for Kentucky, etc. Input must be capitalized. |
whole |
type: text , type: integer , type: number
|
A non-negative integer, including 0. |
word |
type: text |
A text string; may not contain spaces or special characters (accepts underscores). |
zip5 |
type: text , type: integer , type: number
|
Five-digit United States ZIP code. Consider using |
Default input length and field sizes
The following datatypes include built-in max length and text field widths. If need be, use the maxlength
and size
tags, respectively, to override these settings.
Datatype | Maximum Length | Text field size/width (ems) |
capostcode | 7 | 8 |
date_ddmmyy | 8 | 12 |
date_ddmmyyyy | 10 | 12 |
date_mmddyy | 8 | 12 |
date_mmddyyyy | 10 | 12 |
-- | 25 | |
integer | -- | 6 |
number | -- | 8 |
phone | 14 | 18 |
ukpostcode | 8 | 7 |
usstatecode | 2 | 4 |
whole | -- | 6 |
word | -- | 25 |
zip5 | 5 | 6 |
Additional examples
Decimal datatypes
The 'decimal' datatype dictates the number of decimal places a response can contain. A single value specifies that the response must contain that many digits after a decimal. For example, Q1A will only accept a response that goes out two decimal places.
Ranges can be specified with two values, e.g., '1-2', or a single value with a hyphen, e.g., '-2'. The former (as shown in Q1B) indicates the respondent can enter a number with one to two decimal places, whereas the input in Q1C indicates they can enter up to two decimal places.
Date datatypes
The type: date
question type automatically requires responses in a mm/dd/yyyy format. If the date is selected from the calendar pop up instead of manually entering a response, the selection will automatically fit this format. To require a different format, include one of the date datatypes.
Q3 uses the 'date_mmddyy' datatype to require a two-digit year. Q4 meanwhile uses the 'date_ddmmyy' datatype, listing the day before the month. The start date
and end date
tags are also included to restrict the date range that can be entered or selected from the calendar pop up.
Defining multitype tables
The start table
widget is useful for defining more complex tables such as multicolumn or multitype tables. In the example below, though each row requires a text response, rows 2 and 3 use different data types. To define each row independently, we include a full line space between them.
Both 'phone' and 'email' have built-in text field sizes (18 and 25 ems, respectively), but a size
tag could be added to each row's definition to override this if need be. These datatypes are also encrypted automatically, so only those with a Superuser system role will be able to see data for those fields.
Validating a 10 digit phone number
The 'phone' datatype allows for three input lengths: 5, 7, and 10 digit numbers. As such, validations are necessary to force a 10 digit response. In Q6, the validation
uses regex so respondents can only enter a 10 digit number while still allowing variations in formatting. Using hyphens or parentheses around the area code are optional, but spaces are not permitted.
Tip! Separators can be entered, but they will be stored in the data. To remove all separators so that only the digits remain in the data, add the following code to the question:
cvalue: $QX =~ s/\D+//gr
Capturing UK postcodes
It is extremely rare that clients need the full UK postcode, as the first part (the out-code) and the first number of the second part (the in-code) are already accurate enough for consumer market research purposes.
Caution: The datatype: ukpostcode
uses a validation to force respondents to enter their full postcode, which is PII in the UK. Unless the survey includes additional information, capturing the full postcode breaches UK GDPR.
Clients need to explicitly state the reason for requesting the full postcode, how the data will be used, and likely the client or parties with access to the data need to be revealed. Please reach out to an expert to confirm if your survey is complying with the UK's data protection protocols.
Full UK postcode
The 'ukpostcode' datatype will capture the full UK postcode.
7. What is your full postcode?
preface: THIS IS FOR TESTING PURPOSES ONLY.
instructions: Please enter your full postcode, including both the outward-code and inward-code. For example, 'SW1A 0AA'.
type: text
datatype: ukpostcode
Partial UK postcode
In the example below, we demonstrate how to capture a portion of the UK postcode without having to use datatype: ukpostcode
.
QPOSTCODE only requires the out-code and first digit of the in-code for the respondent. The validation
makes sure it follows the proper format. Responses can then be matched to UK postcode spreadsheets for demographic purposes.
POSTCODE. What is your postcode? Please enter the first part, and then the first digit in the second part of your home postcode?
instructions: For example if your full postcode is "AB12 3CD" please enter "AB12 3" including a space. This is to assess the geographic region you live in more accurately. It will only be used to help analyse the results of this survey.
type: text
size: 5
maxlen: 6
cvalue: {uc $QPOSTCODE}
validation: [value] =~ /^[A-Z]{1,2}\d[A-Z\d]?\s\d$/ {message: Please enter the first part of your postcode. For example if your full postcode is "AB12 3CD" please enter "AB12 3" including a space.}
dta: 99. Prefer not to say
Comments
0 comments
Please sign in to leave a comment.