Skip to content

Instantly share code, notes, and snippets.

@jazzedge
Created July 10, 2017 08:10
Show Gist options
  • Select an option

  • Save jazzedge/80a38b43590b4f5a2077105aa75f89e5 to your computer and use it in GitHub Desktop.

Select an option

Save jazzedge/80a38b43590b4f5a2077105aa75f89e5 to your computer and use it in GitHub Desktop.
Bot Email validation
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