Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Commit

Permalink
Finalized regex pattern for email validation in register and contact …
Browse files Browse the repository at this point in the history
…pages
  • Loading branch information
miketvo committed May 4, 2021
1 parent 9072c3d commit 74acf6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion public/js/account/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Validator.email = function (selector, message) {
return {
selector: selector,
test: function (value) {
let regex = /^(([a-zA-Z0-9][.]?){2,})[a-zA-Z0-9]@(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,5})$/;
let regex = /^(([a-zA-Z0-9][.]?){2,}|([a-zA-Z0-9]\.)+)([a-zA-Z0-9]|(?!\.))+?[a-zA-Z0-9]@(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,5})$/;
return regex.test(value) ? undefined : message || 'Valid email has the form [name]@[domain]';
}
};
Expand Down
8 changes: 4 additions & 4 deletions public/js/contact/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FORM.addEventListener("submit", function(event) {


// Create RegExp patterns
const REGEX_EMAIL_CONSOLE_ALERT = /^[^.](([^<>()\[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*){2,}|(.+){2,})@(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,5})$/;
const REGEX_EMAIL_CONSOLE_ALERT = /^(([a-zA-Z0-9][.]?){2,}|([a-zA-Z0-9]\.)+)([a-zA-Z0-9]|(?!\.))+?[a-zA-Z0-9]@(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,5})$/;
const REGEX_PHONE_CONSOLE_ALERT = /^([0-9][-. ]?){9,11}[^-. ]$/;

// Variables
Expand Down Expand Up @@ -55,7 +55,7 @@ FORM.addEventListener("submit", function(event) {
err += errNum + ". Enter Email.\n";
} else {
// If you don't Enter Email address in email pattern format (i already described "REGEX_EMAIL_CONSOLE_ALERT") then see error (Invalid Email)
if(!REGEX_EMAIL_CONSOLE_ALERT.test(EMAIL_CONSOLE_ALERT)){
if(!REGEX_EMAIL_CONSOLE_ALERT.test(EMAIL_CONSOLE_ALERT)) {
errNum++;
err += errNum + ". Invalid Email. Valid email has the form [name]@[domain]\n";
}
Expand Down Expand Up @@ -109,7 +109,7 @@ function updateRequirementMessage() {
let advice;

if (T < 50) {
advice = "Your message needs " + (50-T) + " more letters.";
advice = "Your message needs " + (50 - T) + " more letters.";
document.getElementById('remaining-letters').innerHTML = advice.fontcolor("red");
}
else if (T <= 500) {
Expand Down Expand Up @@ -191,7 +191,7 @@ EMAIL.onblur = function() {
EMAIL.oninput = function() {

// Validate EMAIL_REQUIREMENT
let emailRegEx = /^(([a-zA-Z0-9][.]?){2,})[a-zA-Z0-9]@(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,5})$/;
let emailRegEx = /^(([a-zA-Z0-9][.]?){2,}|([a-zA-Z0-9]\.)+)([a-zA-Z0-9]|(?!\.))+?[a-zA-Z0-9]@(([a-zA-Z0-9]+\.)+[a-zA-Z]{2,5})$/;
if (EMAIL.value.match(emailRegEx)) {
EMAIL_REQUIREMENT.classList.remove("invalid");
EMAIL_REQUIREMENT.classList.add("valid");
Expand Down

0 comments on commit 74acf6b

Please sign in to comment.