Skip to content

Commit 71c4e7d

Browse files
authored
Add support to validate multiple emails (#195)
* Add support to validate multiple emails
1 parent e6e200f commit 71c4e7d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/resources/static/js/subscription.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,20 +827,25 @@ jQuery(document).ready(function () {
827827
$('#notificationMeta').removeClass("is-invalid");
828828
$('#errorExists').hide();
829829

830-
var notoficationMetaIsEmpty = (
830+
var notificationMetaIsEmpty = (
831831
!allowEmpty && notificationMeta == "" || !allowEmpty && notificationMeta.replace(/\s/g, "") == '""');
832-
if (notoficationMetaIsEmpty) {
833-
$('#invalidNotificationMeta').text("NotificationMeta must not be empty");
832+
if (notificationMetaIsEmpty) {
833+
$('#invalidNotificationMeta').text("NotificationMeta must not be empty.");
834834
error = true;
835835
} else if (vm.restPost()) {
836836
//validate url not implemented yet.
837837
} else if (!vm.restPost()) {
838838
// Validate email
839-
var regExpression = /^(([^<>()\[\]\\.,;:\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,}))$/;
840-
var isInvalidEmailAddress = (!regExpression.test(notificationMeta) && notificationMeta != "");
841-
if (isInvalidEmailAddress) {
842-
$('#invalidNotificationMeta').text("Not a valid email.");
843-
error = true;
839+
var emails = notificationMeta.split(",");
840+
for(var email of emails) {
841+
email = email.trim();
842+
var validEmailRegExpression = /^(([^<>()\[\]\\.,;:\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,}))$/;
843+
var isValidEmailAddress = validEmailRegExpression.test(email);
844+
if (!isValidEmailAddress) {
845+
$('#invalidNotificationMeta').text(email + " not a valid email.");
846+
error = true;
847+
break;
848+
}
844849
}
845850
}
846851
if (error) {

0 commit comments

Comments
 (0)