Skip to content

Commit 5f33974

Browse files
author
jmcdougall
committed
feat: add subscribe function
function to ensure the email address is valid when subscribing to the newsletter
1 parent fcc4968 commit 5f33974

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

assets/js/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@
192192
});
193193
});
194194
});
195+
196+
// Ensures valid email is supplied
197+
$(".subscribe").click(function () {
198+
if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(document.getElementById('email').value)) {
199+
document.getElementById('email').value = "Thank you for subscribing to our newsletters."
200+
} else {
201+
document.getElementById('email').value = "Please enter a valid email address."
202+
}
203+
});
195204
})(jQuery);
196205
// News letter Form
197206
// use email

0 commit comments

Comments
 (0)