Accessibility Compliance
SurveyJS libraries meet a variety of WCAG and Section 508 standards. Run AXE® Validation to assess this demo’s accessibility level.

Form Validation

Edit in →
Survey Creator

User input validation is used to ensure that respondents fill out all required form fields and the format of values is correct before they are submitted to the server. This example demonstrates how to configure built-in client-side form input validation.

SurveyJS Form Library supports multiple validator types. Most of them are configured in the validators array. Add one or more objects to it and set their type property to one of the validator types listed in the table below. Refer to the Description column for information on other properties applicable to a specific validator type. All types also support the text property that allows you to override default validation messages.

type Description
"numeric" Throws an error if the answer is not a number or if an entered number is outside the range between minValue and maxValue. Alternatively, you can set the min and max properties in the question object to specify the range.
"text" Throws an error if the length of entered text is outside the range between minLength and maxLength.
"email" Throws an error if an entered value is not a valid e-mail address.
"answercount" Throws an error if a user selects fewer choices than specified by minCount or more choices than specified by maxCount. Applies only to the question types that can have multiple values (for instance, Checkbox).
"regex" Throws an error if an entered value does not match a regular expression defined in the regex property.
"expression" Throws an error when the expression evaluates to false (see Expressions).

Form Library also supports the Required validator, which rejects empty answers. Enable isRequired to require an answer, or use a requiredIf expression to apply this requirement conditionally (see Conditional Visibility). Configure these properties directly on the question, outside the validators array.

For Boolean questions that require a positive answer, such as acceptance of terms and conditions, enable requireTrue instead. It rejects both negative and empty answers, while isRequired rejects only empty answers. Configure requireTrue directly on the question; you do not need to enable isRequired as well.

This example demonstrates the validator types above and an agreement checkbox with requireTrue enabled. Question descriptions explain which values are valid. To see validation errors, enter invalid values, leave required fields empty, or leave the agreement checkbox unchecked, then click Complete.

In this demo, validation is triggered immediately after you leave an input field because the Survey's checkErrorsMode property is set to "onValueChanged". If you do not set this property, validation activates before a user proceeds to the next page or completes the survey.

Your cookie settings

We use cookies to make your browsing experience more convenient and personal. Some cookies are essential, while others help us analyse traffic. Your personal data and cookies may be used for ad personalization. By clicking “Accept All”, you consent to the use of all cookies as described in our Terms of Use and Privacy Statement. You can manage your preferences in “Cookie settings.”

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.