validate email using regex
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user