2
votes

Is there any way of validating the user input which uses context variable?

My context variable stores the email address,so I would like the validation to check for the "@" sign.

Is there any way of doing this?

1
I am facing a problem like when i am using slots the responses is not coming to my android app but it's running fine in it's try it out section. what should i do?Tanmay Sahoo

1 Answers

4
votes

You can use the context variable with regex to extract the e-mail address, and after your code just validate the information, if the variableEmail = context.mail, do it... I cant help you with the code because you did not report your Programmation language.

But, if you want to saves the mail address in a context variable. I made a conversation example so you know how to do it, here are the steps:

Part I:

enter image description here

Part II: enter image description here

Part III: enter image description here

The JSON files

Name example:

 {
      "context": {
        "name": "<? input.text?>"
      },
      "output": {
        "text": {
          "values": [
            "Hi $name, please report your e-mail address."
          ],
          "selection_policy": "sequential"
        }
      }
    }

Mail example:

{
  "context": {
    "mail": "<? input.text.extract('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+(\\.[a-zA-Z]+){1,}',0) ?>"
  },
  "output": {
    "text": {
      "values": [
        "Thanks very much, your name is $name and your mail is $mail."
      ],
      "selection_policy": "sequential"
    }
  }
}

And finnaly, the result is:

enter image description here

If you want knows how to validate mail, search with the programming language you are developing the application and don't forget: the informations is saved inside: context.name or context.mail, according to my example.