Created
July 10, 2017 08:10
-
-
Save jazzedge/80a38b43590b4f5a2077105aa75f89e5 to your computer and use it in GitHub Desktop.
Bot Email validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bot.dialog('email', [ | |
| function (session, results) { | |
| builder.Prompts.text(session, 'What is your email address?'); | |
| }, | |
| function (session, results) { | |
| var validEmail = helpers.isEmailAddress(results.response); | |
| console.log('EMAIL VALIDATION: ', validEmail); | |
| if (validEmail == false) { | |
| session.say('That is not a valid email address.'); | |
| session.replaceDialog('email'); | |
| } else { | |
| session.userData.myEmail = results.response; | |
| console.log('My Email: ' + results.response); | |
| session.userData.dialog = sessionArray[3]; | |
| session.beginDialog(session.userData.dialog); | |
| } | |
| } | |
| ]); | |
| //In a separate helpers.js file: | |
| //Validate email | |
| module.exports = { | |
| isEmailAddress: function(str) { | |
| var pattern = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"; | |
| if (str.match(pattern)) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment