Skip to content

Commit

Permalink
Edit: variable scope
Browse files Browse the repository at this point in the history
This commit will tightly scope variable because it is not referenced anywhere else outside the function.
  • Loading branch information
sazk07 authored Dec 30, 2024
1 parent 21124e6 commit 018d7c1
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,13 @@ const form = document.querySelector("form");
const email = document.getElementById("mail");
const error = email.nextElementSibling;

// As per the HTML Specification
const emailRegExp =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
// create a function that checks if the email is valid,
// sets class names and returns a boolean
const isValidEmail = () => {
// As per the HTML Specification
const emailRegExp =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;

const isValid = email.value.length === 0 || emailRegExp.test(email.value);
// set class name to indicate validity
email.className = isValid ? "valid" : "invalid";
Expand Down

0 comments on commit 018d7c1

Please sign in to comment.