The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to limit the number of characters a user can input in a chatbot

LeBron
Tera Contributor

Hi everyone,

 

I would like to limit the number of characters a user can input in a chatbot.

For instance, if a user inputted over 200 characters, the alert message would show up in a chatbot.

 I tried to create a Virtual Agent Designer by using Script Action which is one of utilities, but it was not correct behaver.

Hopelly, someone help me to create VA Flow correctly. 

 

Thank you

1 ACCEPTED SOLUTION

Chris D
Mega Sage
Mega Sage

In a Text input node, set Input format = Custom then write a simple script as such:

function validate(value) {
    var isValid = true;
    var errorMessage;

    //should be shorter than 200 characters
    if (value.length > 200) {
        isValid =  false;
        errorMessage = 'Sorry, the application name should be 200 characters or less';
    }
    return {
        valid: isValid,
        error: errorMessage
    };
}

ChrisD_0-1721335905358.png

 

Note this validation happens server-side - after the user submits their response - and you cannot do it client-side (before they submit).

View solution in original post

1 REPLY 1

Chris D
Mega Sage
Mega Sage

In a Text input node, set Input format = Custom then write a simple script as such:

function validate(value) {
    var isValid = true;
    var errorMessage;

    //should be shorter than 200 characters
    if (value.length > 200) {
        isValid =  false;
        errorMessage = 'Sorry, the application name should be 200 characters or less';
    }
    return {
        valid: isValid,
        error: errorMessage
    };
}

ChrisD_0-1721335905358.png

 

Note this validation happens server-side - after the user submits their response - and you cannot do it client-side (before they submit).