Validation

To validate the info provided by the visitors. You can validate the following input fields:

  • email - To validate the email address given by the visitor.
  • phoneno - To validate the phone number provided.
  • website - To validate the website address provided.
  • number - To validate the number or to allow just numbers in the field.
  • number(n-m) - To validate the number and you can also specify the "from" and "to" range of the number allowed.
  • string(n-m) - To validate the number and you can also specify the "from" and "to"  to validate the length(number of characters) of the strings allowed.

Note: To mention the error message is your choice. If you skip "error", then the question will repeat without the error message until the visitor input is valid.

 

Use Case:

Context Handler function:

Copiedresult = Map();
response = Map();
response.put("action", "reply");
response.put("replies",[
    {
      "text": "May I have your email address, please? ",
      "validate": {
        "format": "email",
        "error": ["Seems like the value is invalid.","Please enter a valid email address"]
      }
    }
  ]);
prompt = Map();
prompt.put("param_name", "reply");
prompt.put("data", response);
result.put("prompt", prompt);
result.put("todo", "prompt");
return result;

Execution Function:

Copiedresult = Map(); 
response = Map(); 
response.put("action", "reply"); 
response.put("replies",[ { "text": "May I have your email address, please? ", "validate": { "format": "email", "error": ["Seems like the value is invalid.","Please enter a valid email address"] } } ]); 
prompt = Map(); 
prompt.put("param_name", "reply"); 
prompt.put("data", response); 
result.put("prompt", prompt); 
result.put("todo", "prompt"); 
return result;

Output: