Refactor JS email regexp to be accessible from every page MAILPOET-1288
This commit is contained in:
@@ -209,7 +209,7 @@ define(
|
||||
for (column in rowData) {
|
||||
emailAddress = detectAndCleanupEmail(rowData[column]);
|
||||
if (emailColumnPosition === null
|
||||
&& window.emailRegex.test(emailAddress)) {
|
||||
&& window.mailpoet_email_regex.test(emailAddress)) {
|
||||
emailColumnPosition = column;
|
||||
// add current e-mail to an object index
|
||||
parsedEmails[emailAddress] = true;
|
||||
@@ -229,7 +229,7 @@ define(
|
||||
if (_.has(parsedEmails, email)) {
|
||||
duplicateEmails.push(email);
|
||||
}
|
||||
else if (!window.emailRegex.test(email)) {
|
||||
else if (!window.mailpoet_email_regex.test(email)) {
|
||||
invalidEmails.push(rowData[emailColumnPosition]);
|
||||
}
|
||||
// if we haven't yet processed this e-mail and it passed
|
||||
@@ -257,7 +257,7 @@ define(
|
||||
// since we assume that the header line is always present, we need
|
||||
// to detect the header by checking if it contains a valid e-mail address
|
||||
window.importData.step1 = {
|
||||
header: (!window.emailRegex.test(
|
||||
header: (!window.mailpoet_email_regex.test(
|
||||
processedSubscribers[0][emailColumnPosition])
|
||||
) ? processedSubscribers.shift() : null,
|
||||
subscribers: processedSubscribers,
|
||||
@@ -690,7 +690,7 @@ define(
|
||||
columnData = helperSubscribers.subscribers[0][i];
|
||||
columnId = 'ignore'; // set default column type
|
||||
// if the column is not undefined and has a valid e-mail, set type as email
|
||||
if (columnData % 1 !== 0 && window.emailRegex.test(columnData)) {
|
||||
if (columnData % 1 !== 0 && window.mailpoet_email_regex.test(columnData)) {
|
||||
columnId = 'email';
|
||||
} else if (helperSubscribers.header) {
|
||||
headerName = helperSubscribers.header[i];
|
||||
@@ -791,7 +791,9 @@ define(
|
||||
// EMAIL filter: if the first value in the column doesn't have a valid
|
||||
// email, hide the next button
|
||||
if (column.id === 'email') {
|
||||
if (!window.emailRegex.test(subscribersClone.subscribers[0][matchedColumn.index])) {
|
||||
if (!window.mailpoet_email_regex.test(
|
||||
subscribersClone.subscribers[0][matchedColumn.index])
|
||||
) {
|
||||
preventNextStep = true;
|
||||
if (!jQuery('[data-id="notice_invalidEmail"]').length) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('columnContainsInvalidElement'), {
|
||||
|
@@ -48,6 +48,8 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
||||
var mailpoet_premium_version = <%= json_encode(mailpoet_premium_version()) %>;
|
||||
var mailpoet_analytics_enabled = <%= is_analytics_enabled() | json_encode %>;
|
||||
var mailpoet_analytics_data = <%= json_encode(get_analytics_data()) %>;
|
||||
// RFC 5322 standard; http://emailregex.com/
|
||||
var mailpoet_email_regex = /^(([^<>()\[\]\\.,;:\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,}))$/;
|
||||
</script>
|
||||
|
||||
<!-- javascripts -->
|
||||
|
@@ -59,8 +59,6 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
// RFC 5322 standard; http://emailregex.com/
|
||||
emailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/;
|
||||
jQuery(function($) {
|
||||
// on dom loaded
|
||||
$(function() {
|
||||
@@ -68,7 +66,7 @@
|
||||
$('#mailpoet_settings_form').on('submit', function() {
|
||||
// Check if filled emails are valid
|
||||
var invalidEmails = $.map($('#mailpoet_settings_form')[0].elements, function(el) {
|
||||
return el.type === 'email' && el.value && !window.emailRegex.test(el.value) ? el.value : null;
|
||||
return el.type === 'email' && el.value && !window.mailpoet_email_regex.test(el.value) ? el.value : null;
|
||||
}).filter(function(val) { return !!val; });
|
||||
if (invalidEmails.length) {
|
||||
MailPoet.Notice.error(
|
||||
|
@@ -24,9 +24,7 @@
|
||||
importData = {},
|
||||
mailpoetColumnsSelect2 = <%= subscriberFieldsSelect2|raw %>,
|
||||
mailpoetColumns = <%= subscriberFields|raw %>,
|
||||
mailpoetSegments = <%= segments|raw %>,
|
||||
// RFC 5322 standard; http://emailregex.com/
|
||||
emailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/;
|
||||
mailpoetSegments = <%= segments|raw %>
|
||||
</script>
|
||||
<% endblock %>
|
||||
|
||||
|
Reference in New Issue
Block a user