forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PromptStringRegex.cs
31 lines (26 loc) · 1.13 KB
/
PromptStringRegex.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace ContosoFlowers.BotAssets.Dialogs
{
using System;
using System.Text.RegularExpressions;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Connector;
using Properties;
[Serializable]
public class PromptStringRegex : Prompt<string, string>
{
private readonly Regex regex;
public PromptStringRegex(string prompt, string regexPattern, string retry = null)
: base(new PromptOptions<string>(prompt, retry))
{
this.regex = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
}
protected override bool TryParse(IMessageActivity message, out string result)
{
var quitCondition = message.Text.Equals("B", StringComparison.InvariantCultureIgnoreCase) || message.Text.Equals("Back", StringComparison.InvariantCultureIgnoreCase);
var validEmail = this.regex.Match(message.Text).Success;
result = validEmail ? message.Text : null;
return validEmail || quitCondition;
}
}
}