Reputation: 77
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?
Upvotes: 2
Views: 1016
Reputation: 5330
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:
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:
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.
Upvotes: 4