From 2ae87c8090822f455e041d833a234e29bbbe77a7 Mon Sep 17 00:00:00 2001 From: mark burdett Date: Wed, 3 Jun 2020 08:36:02 -0700 Subject: [PATCH] Client-side email validation for congress messages Refs #829 --- .../javascripts/application/tools/congress_message.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/javascripts/application/tools/congress_message.js b/app/assets/javascripts/application/tools/congress_message.js index 8d02bcc1d..c1c155291 100644 --- a/app/assets/javascripts/application/tools/congress_message.js +++ b/app/assets/javascripts/application/tools/congress_message.js @@ -37,6 +37,12 @@ $(document).on("ready", function() { }); $("#congress-message-tool").on("click", "#to-page-3", function(){ + // Run browser email validation, plus additional check for valid hostname. + if (!$('#common_attributes__EMAIL')[0].checkValidity() || !/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i.test($('#common_attributes__EMAIL').val())) { + show_error('Please double-check your email address and try again.', $('.rep-info')); + $(window).scrollTop($('.rep-info').offset().top); + return; + } $(".rep-info").hide(); $("#customize-message").show(); if ($("#action-content").length) {