validate email using regex

This commit is contained in:
GotPPay
2018-01-19 20:05:49 +01:00
parent 0727328e58
commit 00272ec67d
2 changed files with 9 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
const nodemailer = require ('nodemailer'); const nodemailer = require ('nodemailer');
module.exports = { module.exports = {
validateEmailFromAlexaResponse: function (email) { transformEmailFromAlexaResponse: function (email) {
//email from alexa response will contain words instead of symbols, like : //email from alexa response will contain words instead of symbols, like :
//at = @ //at = @
//underscore = _ //underscore = _
@@ -14,10 +14,13 @@ module.exports = {
.replace (/dash/gi, '-') .replace (/dash/gi, '-')
.replace (/dot/gi, '.'); .replace (/dot/gi, '.');
//Validate here with some email validation regex return transformedEmail;
},
//return true if email is valid isEmailValid : function(email){
return true; let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return validEmailRegex.test(email);
}, },
sendEmal: function (name, fromEmail, message, toEmail) { sendEmal: function (name, fromEmail, message, toEmail) {

View File

@@ -88,8 +88,9 @@ module.exports = {
repromptSpeech repromptSpeech
); );
} else if (!intent.slots.Message.value) { } else if (!intent.slots.Message.value) {
intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse(intent.slots.Message.value);
if ( if (
!emailHelper.validateEmailFromAlexaResponse ( !emailHelper.isEmailValid (
intent.slots.Email.value intent.slots.Email.value
) )
) { ) {