'How to check multiple function in JavaScript

I have many functions written in JavaScript such as userName(), password() etc. But on submitting on the form, I have a single function return formValidator();.

I want function to call all the other functions and check whether they are returning false or not. If they all are true than it should return true, otherwise it should return false.

function userName(){
      var x=document.forms["signupform"]["firstname"].value;
            if(x=="" ||x==null){
           document.getElementById("firstname").style.border="1px solid #F50A0A";
           document.getElementById("firstname").style.boxShadow="2px 2px 5px #F50A0A";
           return false;
      }else {return true;}
}

function password(){
 var z=document.forms["signupform"]["password"].value;
      if(z=="" ||z==null){
            document.getElementById("password").style.border="1px solid #F50A0A";
           document.getElementById("password").style.boxShadow="2px 2px 5px #F50A0A";
            return false;
      }else {return true;}
}


Solution 1:[1]

You can call each function, using the && operator to indicate that each one must return something that evaluates to true. If any one of them returns something that evaluates to false, the entire statement will evaluate to false:

function formValidator() {
    return userName() && password() && somethingElse() && etc();
}

Solution 2:[2]

var validators = [userName, password, ...];
function formValidator() {
    return validators.every(function(fn){return fn();});
}

or just use the AND operator:

function formValidator() {
    return userName() && password() && ...;
}

Solution 3:[3]

It should be as simple as:

function formValidator()
{
    var username = userName();
    var password = password();

    return username && password; // or just return userName() && password();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Allardice
Solution 2 Bergi
Solution 3 rlemon