From fb97801d17b2f5b1af7d7ebe413436b6c41f1bbf Mon Sep 17 00:00:00 2001 From: Dave Convery Date: Thu, 1 Oct 2020 08:49:39 +0100 Subject: [PATCH 1/4] Test Salesforce email validation regex --- src/forms/js/honeycomb.forms.marketo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/forms/js/honeycomb.forms.marketo.js b/src/forms/js/honeycomb.forms.marketo.js index 829937b6..7c21f46c 100644 --- a/src/forms/js/honeycomb.forms.marketo.js +++ b/src/forms/js/honeycomb.forms.marketo.js @@ -179,9 +179,9 @@ const create = c => { // Email validation. if (typeof fields.Email !== 'undefined') { - // Email regex provided by https://regex101.com/r/L9Z2N0/1. - // Check that the format is {something}@{something}.{something}. - const emailRegex = /\S+@\S+\.\S+/; + // Email regex provided by https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/using_regular_expressions_to_validate_email_addresses.htm. + // Check that the format is acceptable to Salesforce (only valid salesforce characters, single @, at least one . character in domain). + const emailRegex = "^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$" ; if (emailRegex.test(fields.Email) === false) { fail.isFail = true; From e67b18a26c682020c1986951f6126cb0275fb10d Mon Sep 17 00:00:00 2001 From: Dave Convery Date: Thu, 1 Oct 2020 13:23:34 +0100 Subject: [PATCH 2/4] Update honeycomb.forms.marketo.js --- src/forms/js/honeycomb.forms.marketo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forms/js/honeycomb.forms.marketo.js b/src/forms/js/honeycomb.forms.marketo.js index 7c21f46c..c5beee23 100644 --- a/src/forms/js/honeycomb.forms.marketo.js +++ b/src/forms/js/honeycomb.forms.marketo.js @@ -181,7 +181,7 @@ const create = c => { // Email regex provided by https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/using_regular_expressions_to_validate_email_addresses.htm. // Check that the format is acceptable to Salesforce (only valid salesforce characters, single @, at least one . character in domain). - const emailRegex = "^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$" ; + const emailRegex = '^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$' ; if (emailRegex.test(fields.Email) === false) { fail.isFail = true; From abc236d287e7715eeea1efb3c62105d5948f4702 Mon Sep 17 00:00:00 2001 From: Dave Convery Date: Fri, 2 Oct 2020 14:13:26 +0100 Subject: [PATCH 3/4] Add Salesforce validation --- src/forms/js/honeycomb.forms.marketo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forms/js/honeycomb.forms.marketo.js b/src/forms/js/honeycomb.forms.marketo.js index c5beee23..2ddb08e1 100644 --- a/src/forms/js/honeycomb.forms.marketo.js +++ b/src/forms/js/honeycomb.forms.marketo.js @@ -181,7 +181,7 @@ const create = c => { // Email regex provided by https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/using_regular_expressions_to_validate_email_addresses.htm. // Check that the format is acceptable to Salesforce (only valid salesforce characters, single @, at least one . character in domain). - const emailRegex = '^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$' ; + const emailRegex = RegExp('^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$') ; if (emailRegex.test(fields.Email) === false) { fail.isFail = true; From b075def124abd9d65c2d7fcd4436bcab421c58c1 Mon Sep 17 00:00:00 2001 From: Dave Convery Date: Tue, 6 Oct 2020 16:57:36 +0100 Subject: [PATCH 4/4] Switch validation to work against lowercase result --- src/forms/js/honeycomb.forms.marketo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forms/js/honeycomb.forms.marketo.js b/src/forms/js/honeycomb.forms.marketo.js index 2ddb08e1..c591034a 100644 --- a/src/forms/js/honeycomb.forms.marketo.js +++ b/src/forms/js/honeycomb.forms.marketo.js @@ -183,7 +183,7 @@ const create = c => { // Check that the format is acceptable to Salesforce (only valid salesforce characters, single @, at least one . character in domain). const emailRegex = RegExp('^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$') ; - if (emailRegex.test(fields.Email) === false) { + if (emailRegex.test(fields.Email.toLowerCase()) === false) { fail.isFail = true; fail.message = 'Please enter a valid email address.'; fail.element = marketoForm.getFormElem().find('input[name="Email"]');