From 1df3495b708fe0d0ce1cc52d470a189d8e922769 Mon Sep 17 00:00:00 2001 From: trustidkid Date: Tue, 9 Jun 2020 10:55:18 +0100 Subject: [PATCH 1/2] feat: added mail validator --- api/tests/test.js | 7 +++++++ api/utils/mail_validator.js | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/api/tests/test.js b/api/tests/test.js index e69de29..e16ff9a 100644 --- a/api/tests/test.js +++ b/api/tests/test.js @@ -0,0 +1,7 @@ +function ValidateEmail(mail) { + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)) { + return (true) + } + alert("You have entered an invalid email address!") + return (false) +} \ No newline at end of file diff --git a/api/utils/mail_validator.js b/api/utils/mail_validator.js index e69de29..4bde417 100644 --- a/api/utils/mail_validator.js +++ b/api/utils/mail_validator.js @@ -0,0 +1,12 @@ +function ValidateEmail(email) { + var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; + if (email.value.match(mailformat)) { + //change the input tag to focus + document.form.text.focus(); + return true; + } else { + alert("You have entered an invalid email address!"); + document.form.text.focus(); + return false; + } +} \ No newline at end of file From cd22231f56f173dabe35af8e67e9c33a8b38dae9 Mon Sep 17 00:00:00 2001 From: trustidkid Date: Tue, 9 Jun 2020 10:58:57 +0100 Subject: [PATCH 2/2] modified the email format string --- api/tests/test.js | 2 +- api/utils/mail_validator.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/tests/test.js b/api/tests/test.js index e16ff9a..28ea815 100644 --- a/api/tests/test.js +++ b/api/tests/test.js @@ -1,5 +1,5 @@ function ValidateEmail(mail) { - if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)) { + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.emailAddr.value)) { return (true) } alert("You have entered an invalid email address!") diff --git a/api/utils/mail_validator.js b/api/utils/mail_validator.js index 4bde417..df24ca8 100644 --- a/api/utils/mail_validator.js +++ b/api/utils/mail_validator.js @@ -1,5 +1,5 @@ function ValidateEmail(email) { - var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; + var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/; if (email.value.match(mailformat)) { //change the input tag to focus document.form.text.focus();