Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

How to create a validator function that calls two functions to confirm login (email/passwd) info?

$
0
0

I have two functions created already (isEmailValid & isPasswordValid) below which I could use some feedback on as well.I'm supposed to have them return a boolean value (if they follow the correct format). This would then get passed on to the Validator function which is supposed to analyze a loadData function with entries in LocalStorage to see if the email/password combo matches.

Email & Password Functions:

function isEmailValid(email) {
        var res1;
    var emailText = document.email.value;
    var pattern = /^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*@[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/;
    if (pattern.test(emailText)) 
            {
            res1 = "TRUE";
        } else {
            res1 = "FALSE";
        }
}

function isPasswordValid(passwd) { 
     var res2; 
     var str = document.passwd.value; 
     if (str.match(/[a-z]/g) && str.match(/[A-Z]/g) && str.match(/[0-9]/g) && str.match(/[^a-zA-Z\d]/g) && str.length >= 8) 
            res2 = "TRUE"; 
     else 
            res2 = "FALSE"; 
                            }

loadData function

function loadData()
{
  var coordinators = [
     {
        email: "jjd@gmail.com",
        firstName: "Jennifer",
        lastname: "Davis",
        role: "instructor",
        password:"anoth3rpass"
   },

   {
      email: "boss_man@yahoo.com",
      firstName: "Anderson",
      surname: "Alleyne",
      role: "instructor",
      password:"passw0rd"
   }
  ]

  var students = [
   {
      year: "2018",
      student_id: "220249309",
      firstName: "Merissa",
      lastName: "Halliwall",
      email: "mm_h@hotmail.com",
      password:"f1rstpa55",
      address: "Lodge Road Ch Ch"
   },

   {
      year: "2020",
      student_id: "408306622",
      firstName: "Vanda",
      lastName: "Marshall",
      email: "vmarhsall@guardian.co.uk",
      password:"oll1p0ps",
      address: "Sargeants Village Tenantry Ch Ch"
   },

   {
      year: "2019",
      student_id: "210350493",
      firstName: "Mark",
      lastName: "Belgrave",
      email: "bboy89@hotmail.com",
      password:"246bajan",
      address: "76 Edghill Terrace"
   },

   {
      year: "2020",
      student_id: "200006059",
      firstName: "Pamale",
      lastName: "Gaskin",
      email: "pamgask99@gmail.com",
      password:"pamal3gask",
      address: "Lot 33 The Belle"
   }
}

  //add to localStorage 
  if(!localStorage.getItem("coordinators"))
  {
     localStorage.setItem("coordinators", JSON.stringify(coordinators));
  }
  if(!localStorage.getItem("students"))
  {
     localStorage.setItem("students", JSON.stringify(students));
  }

}

There are coordinators (admins) and students. I'm supposed to have the login page take you to different sites depending on which you are.

I am just a bit lost on how to create the Validator function...


Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>