Custom Validators

Create custom validator

                        var MyTextValidator = (function (_super) {
    Survey.__extends(MyTextValidator, _super);
    function MyTextValidator() {;
    MyTextValidator.prototype.getType = function () { return "mytextvalidator"; };
    MyTextValidator.prototype.validate = function (value, name) {
        if(value.indexOf("survey") < 0) {
            //report an error
            return new Survey.ValidatorResult(null, new Survey.CustomError(this.getErrorText(name)));
        //return Survey.ValidatorResult object if you want to correct the entered value
        // return new Survey.ValidatorResult(youCorrectedValue);
        //return nothing if there is no any error.
        return null;
    //the default error text. It shows if user do not set the 'text' property
    MyTextValidator.prototype.getDefaultErrorText = function(name) {
        return "You text should contains 'survey' word.";
    return MyTextValidator;
Survey.MyTextValidator = MyTextValidator;
//add into survey Json metaData
Survey.JsonObject.metaData.addClass("mytextvalidator", [], function () { return new MyTextValidator(); }, "surveyvalidator");


var json = {
    questions: [
            { type: "comment",  name: "memo", isRequired: true,
            title: "Type here 'survey' to pass the validation ",
            validators: [{type: "mytextvalidator"}]}

window.survey = new Survey.Model(json);

survey.onComplete.add(function(result) {
    document.querySelector('#surveyResult').innerHTML = "result: " + JSON.stringify(;

    model: survey 

<!DOCTYPE html>
    <title>Create custom validator, jQuery Survey Library Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src=""></script>
<script src=""></script>
<link href="" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">

                <div id="surveyElement">
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>